{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/siddhi/pulls/comments/44127675","id":44127675,"diff_hunk":"@@ -0,0 +1,170 @@\n+/*\n+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.\n+ *\n+ * WSO2 Inc. licenses this file to you under the Apache License,\n+ * Version 2.0 (the \"License\"); you may not use this file except\n+ * in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied. See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.wso2.siddhi.extension.time;\n+\n+import org.apache.commons.lang3.time.FastDateFormat;\n+import org.apache.log4j.Logger;\n+import org.wso2.siddhi.core.config.ExecutionPlanContext;\n+import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException;\n+import org.wso2.siddhi.core.executor.ExpressionExecutor;\n+import org.wso2.siddhi.core.executor.function.FunctionExecutor;\n+import org.wso2.siddhi.extension.time.util.TimeExtensionConstants;\n+import org.wso2.siddhi.query.api.definition.Attribute;\n+import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException;\n+\n+import java.text.DateFormat;\n+import java.text.ParseException;\n+import java.text.SimpleDateFormat;\n+import java.util.Date;\n+\n+/**\n+ * dayOfWeek(dateValue,dateFormat)\n+ * Returns date part from a date or date/time expression.\n+ * dateValue - value of date. eg: \"2014-11-11 13:23:44.657\", \"2014-11-11\"\n+ * dateFormat - Date format of the provided date value. eg: yyyy-MM-dd HH:mm:ss.SSS\n+ * Accept Type(s) for dayOfWeek(dateValue,dateFormat):\n+ * dateValue : STRING\n+ * dateFormat : STRING\n+ * Return Type(s): STRING\n+ */\n+public class ExtractDayOfWeekFunctionExtension extends FunctionExecutor {\n+\n+    private static final Logger log = Logger.getLogger(ExtractDayOfWeekFunctionExtension.class);\n+    private Attribute.Type returnType = Attribute.Type.STRING;\n+\n+    @Override\n+    protected void init(ExpressionExecutor[] attributeExpressionExecutors,\n+                        ExecutionPlanContext executionPlanContext) {\n+        if (attributeExpressionExecutors.length > 2) {\n+            throw new ExecutionPlanValidationException(\"Invalid no of arguments passed to time:dayOfWeek(dateValue,\" +\n+                    \"dateFormat) function, \" + \"required 2, but found \" + attributeExpressionExecutors.length);\n+        }\n+        if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) {\n+            throw new ExecutionPlanValidationException(\"Invalid parameter type found for the first argument of \" +\n+                    \"time:dayOfWeek(dateValue,dateFormat) function, \" + \"required \" + Attribute.Type.STRING +\n+                    \" but found \" + attributeExpressionExecutors[0].getReturnType().toString());\n+        }\n+        //User can omit sending the dateFormat thus using a default CEP Time format\n+        if (attributeExpressionExecutors.length > 0) {\n+            if (attributeExpressionExecutors.length > 1 && attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {\n+                throw new ExecutionPlanValidationException(\"Invalid parameter type found for the second argument of \" +\n+                        \"time:dayOfWeek(dateValue,dateFormat) function, \" + \"required \" + Attribute.Type.STRING +\n+                        \" but found \" + attributeExpressionExecutors[1].getReturnType().toString());\n+            }\n+        }\n+\n+    }\n+\n+    // this method will be executed for two or more parameters\n+    @Override\n+    protected Object execute(Object[] data) {\n+        String userFormat;\n+        if (data[0] == null) {\n+            throw new ExecutionPlanRuntimeException(\"Invalid input given to time:dayOfWeek(dateValue,\" +\n+                    \"dateFormat) function\" + \". First \" + \"argument cannot be null\");\n+        }\n+        if (data.length > 1) {\n+            if (data[1] == null) {\n+                throw new ExecutionPlanRuntimeException(\n+                        \"Invalid input given to time:dayOfWeek(dateValue,dateFormat) function\" + \". Second \" +\n+                                \"argument cannot be null\");\n+            } else {\n+                userFormat = (String) data[1];\n+            }\n+        } else {\n+            userFormat = TimeExtensionConstants.EXTENSION_TIME_DEFAULT_DATE_FORMAT;\n+        }\n+        String source = null;\n+        FastDateFormat userSpecificFormat;\n+        Date userSpecifiedDate;\n+        try {\n+            source = (String) data[0];\n+            userSpecificFormat = FastDateFormat.getInstance(userFormat);\n+            userSpecifiedDate = userSpecificFormat.parse(source);\n+            return getDayOfWeek(userSpecifiedDate);\n+        } catch (ParseException e) {\n+            String errorMsg = \"Provided format \" + userFormat + \" does not match with the timestamp \" + source + e\n+                    .getMessage();\n+            throw new ExecutionPlanRuntimeException(errorMsg, e);\n+        } catch (ClassCastException e) {\n+            String errorMsg = \"Provided Data type cannot be cast to desired format. \" + e.getMessage();\n+            throw new ExecutionPlanRuntimeException(errorMsg, e);\n+        }\n+    }\n+\n+\n+    // this method will be executed for a single parameter\n+    @Override\n+    protected Object execute(Object data) {\n+        String userFormat;\n+        if (data == null) {\n+            throw new ExecutionPlanRuntimeException(\"Invalid input given to time:dayOfWeek(dateValue,\" +\n+                    \"dateFormat) function\" + \". First \" + \"argument cannot be null\");\n+        }\n+        userFormat = (String) data;","path":"modules/siddhi-extensions/time/src/main/java/org/wso2/siddhi/extension/time/ExtractDayOfWeekFunctionExtension.java","position":120,"original_position":120,"commit_id":"48b76344362bcf6d9d502614b4a8c7d064df8464","original_commit_id":"48b76344362bcf6d9d502614b4a8c7d064df8464","user":{"login":"lasanthafdo","id":4602737,"avatar_url":"https://avatars.githubusercontent.com/u/4602737?v=3","gravatar_id":"","url":"https://api.github.com/users/lasanthafdo","html_url":"https://github.com/lasanthafdo","followers_url":"https://api.github.com/users/lasanthafdo/followers","following_url":"https://api.github.com/users/lasanthafdo/following{/other_user}","gists_url":"https://api.github.com/users/lasanthafdo/gists{/gist_id}","starred_url":"https://api.github.com/users/lasanthafdo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lasanthafdo/subscriptions","organizations_url":"https://api.github.com/users/lasanthafdo/orgs","repos_url":"https://api.github.com/users/lasanthafdo/repos","events_url":"https://api.github.com/users/lasanthafdo/events{/privacy}","received_events_url":"https://api.github.com/users/lasanthafdo/received_events","type":"User","site_admin":false},"body":"@minudika \r\nIn this method, it seems you are assigning the same value for both dateFormat and dateValue. Since this method gets executed only for a single parameter, I think the dateFormat should be fixed and only the dateValue should be considered.","created_at":"2015-11-06T11:26:29Z","updated_at":"2015-11-06T11:26:29Z","html_url":"https://github.com/wso2/siddhi/pull/90#discussion_r44127675","pull_request_url":"https://api.github.com/repos/wso2/siddhi/pulls/90","_links":{"self":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/comments/44127675"},"html":{"href":"https://github.com/wso2/siddhi/pull/90#discussion_r44127675"},"pull_request":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/siddhi/pulls/90","id":49935394,"html_url":"https://github.com/wso2/siddhi/pull/90","diff_url":"https://github.com/wso2/siddhi/pull/90.diff","patch_url":"https://github.com/wso2/siddhi/pull/90.patch","issue_url":"https://api.github.com/repos/wso2/siddhi/issues/90","number":90,"state":"open","locked":false,"title":"CEP-1365 fixed ","user":{"login":"minudika","id":6940029,"avatar_url":"https://avatars.githubusercontent.com/u/6940029?v=3","gravatar_id":"","url":"https://api.github.com/users/minudika","html_url":"https://github.com/minudika","followers_url":"https://api.github.com/users/minudika/followers","following_url":"https://api.github.com/users/minudika/following{/other_user}","gists_url":"https://api.github.com/users/minudika/gists{/gist_id}","starred_url":"https://api.github.com/users/minudika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minudika/subscriptions","organizations_url":"https://api.github.com/users/minudika/orgs","repos_url":"https://api.github.com/users/minudika/repos","events_url":"https://api.github.com/users/minudika/events{/privacy}","received_events_url":"https://api.github.com/users/minudika/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-06T10:05:04Z","updated_at":"2015-11-06T11:26:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"27ae0a39c9b9158fe3d142ea300e7c7b79eca688","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2/siddhi/pulls/90/commits","review_comments_url":"https://api.github.com/repos/wso2/siddhi/pulls/90/comments","review_comment_url":"https://api.github.com/repos/wso2/siddhi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/siddhi/issues/90/comments","statuses_url":"https://api.github.com/repos/wso2/siddhi/statuses/48b76344362bcf6d9d502614b4a8c7d064df8464","head":{"label":"minudika:master","ref":"master","sha":"48b76344362bcf6d9d502614b4a8c7d064df8464","user":{"login":"minudika","id":6940029,"avatar_url":"https://avatars.githubusercontent.com/u/6940029?v=3","gravatar_id":"","url":"https://api.github.com/users/minudika","html_url":"https://github.com/minudika","followers_url":"https://api.github.com/users/minudika/followers","following_url":"https://api.github.com/users/minudika/following{/other_user}","gists_url":"https://api.github.com/users/minudika/gists{/gist_id}","starred_url":"https://api.github.com/users/minudika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minudika/subscriptions","organizations_url":"https://api.github.com/users/minudika/orgs","repos_url":"https://api.github.com/users/minudika/repos","events_url":"https://api.github.com/users/minudika/events{/privacy}","received_events_url":"https://api.github.com/users/minudika/received_events","type":"User","site_admin":false},"repo":{"id":45461137,"name":"siddhi","full_name":"minudika/siddhi","owner":{"login":"minudika","id":6940029,"avatar_url":"https://avatars.githubusercontent.com/u/6940029?v=3","gravatar_id":"","url":"https://api.github.com/users/minudika","html_url":"https://github.com/minudika","followers_url":"https://api.github.com/users/minudika/followers","following_url":"https://api.github.com/users/minudika/following{/other_user}","gists_url":"https://api.github.com/users/minudika/gists{/gist_id}","starred_url":"https://api.github.com/users/minudika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minudika/subscriptions","organizations_url":"https://api.github.com/users/minudika/orgs","repos_url":"https://api.github.com/users/minudika/repos","events_url":"https://api.github.com/users/minudika/events{/privacy}","received_events_url":"https://api.github.com/users/minudika/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/minudika/siddhi","description":"Siddhi CEP is a lightweight, easy-to-use Open Source Complex Event Processing Engine (CEP) ","fork":true,"url":"https://api.github.com/repos/minudika/siddhi","forks_url":"https://api.github.com/repos/minudika/siddhi/forks","keys_url":"https://api.github.com/repos/minudika/siddhi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/minudika/siddhi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/minudika/siddhi/teams","hooks_url":"https://api.github.com/repos/minudika/siddhi/hooks","issue_events_url":"https://api.github.com/repos/minudika/siddhi/issues/events{/number}","events_url":"https://api.github.com/repos/minudika/siddhi/events","assignees_url":"https://api.github.com/repos/minudika/siddhi/assignees{/user}","branches_url":"https://api.github.com/repos/minudika/siddhi/branches{/branch}","tags_url":"https://api.github.com/repos/minudika/siddhi/tags","blobs_url":"https://api.github.com/repos/minudika/siddhi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/minudika/siddhi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/minudika/siddhi/git/refs{/sha}","trees_url":"https://api.github.com/repos/minudika/siddhi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/minudika/siddhi/statuses/{sha}","languages_url":"https://api.github.com/repos/minudika/siddhi/languages","stargazers_url":"https://api.github.com/repos/minudika/siddhi/stargazers","contributors_url":"https://api.github.com/repos/minudika/siddhi/contributors","subscribers_url":"https://api.github.com/repos/minudika/siddhi/subscribers","subscription_url":"https://api.github.com/repos/minudika/siddhi/subscription","commits_url":"https://api.github.com/repos/minudika/siddhi/commits{/sha}","git_commits_url":"https://api.github.com/repos/minudika/siddhi/git/commits{/sha}","comments_url":"https://api.github.com/repos/minudika/siddhi/comments{/number}","issue_comment_url":"https://api.github.com/repos/minudika/siddhi/issues/comments{/number}","contents_url":"https://api.github.com/repos/minudika/siddhi/contents/{+path}","compare_url":"https://api.github.com/repos/minudika/siddhi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/minudika/siddhi/merges","archive_url":"https://api.github.com/repos/minudika/siddhi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/minudika/siddhi/downloads","issues_url":"https://api.github.com/repos/minudika/siddhi/issues{/number}","pulls_url":"https://api.github.com/repos/minudika/siddhi/pulls{/number}","milestones_url":"https://api.github.com/repos/minudika/siddhi/milestones{/number}","notifications_url":"https://api.github.com/repos/minudika/siddhi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/minudika/siddhi/labels{/name}","releases_url":"https://api.github.com/repos/minudika/siddhi/releases{/id}","created_at":"2015-11-03T11:09:17Z","updated_at":"2015-11-06T06:44:12Z","pushed_at":"2015-11-06T10:02:11Z","git_url":"git://github.com/minudika/siddhi.git","ssh_url":"git@github.com:minudika/siddhi.git","clone_url":"https://github.com/minudika/siddhi.git","svn_url":"https://github.com/minudika/siddhi","homepage":"http://wso2.com/products/complex-event-processor/","size":16506,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wso2:master","ref":"master","sha":"08c78dee6533bb55441bd651136c381e42374f39","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":18988631,"name":"siddhi","full_name":"wso2/siddhi","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/siddhi","description":"","fork":false,"url":"https://api.github.com/repos/wso2/siddhi","forks_url":"https://api.github.com/repos/wso2/siddhi/forks","keys_url":"https://api.github.com/repos/wso2/siddhi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/siddhi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/siddhi/teams","hooks_url":"https://api.github.com/repos/wso2/siddhi/hooks","issue_events_url":"https://api.github.com/repos/wso2/siddhi/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/siddhi/events","assignees_url":"https://api.github.com/repos/wso2/siddhi/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/siddhi/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/siddhi/tags","blobs_url":"https://api.github.com/repos/wso2/siddhi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/siddhi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/siddhi/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/siddhi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/siddhi/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/siddhi/languages","stargazers_url":"https://api.github.com/repos/wso2/siddhi/stargazers","contributors_url":"https://api.github.com/repos/wso2/siddhi/contributors","subscribers_url":"https://api.github.com/repos/wso2/siddhi/subscribers","subscription_url":"https://api.github.com/repos/wso2/siddhi/subscription","commits_url":"https://api.github.com/repos/wso2/siddhi/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/siddhi/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/siddhi/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/siddhi/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/siddhi/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/siddhi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/siddhi/merges","archive_url":"https://api.github.com/repos/wso2/siddhi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/siddhi/downloads","issues_url":"https://api.github.com/repos/wso2/siddhi/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/siddhi/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/siddhi/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/siddhi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/siddhi/labels{/name}","releases_url":"https://api.github.com/repos/wso2/siddhi/releases{/id}","created_at":"2014-04-21T09:51:36Z","updated_at":"2015-11-05T16:13:35Z","pushed_at":"2015-11-06T10:05:04Z","git_url":"git://github.com/wso2/siddhi.git","ssh_url":"git@github.com:wso2/siddhi.git","clone_url":"https://github.com/wso2/siddhi.git","svn_url":"https://github.com/wso2/siddhi","homepage":null,"size":16506,"stargazers_count":99,"watchers_count":99,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":84,"mirror_url":null,"open_issues_count":8,"forks":84,"open_issues":8,"watchers":99,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/90"},"html":{"href":"https://github.com/wso2/siddhi/pull/90"},"issue":{"href":"https://api.github.com/repos/wso2/siddhi/issues/90"},"comments":{"href":"https://api.github.com/repos/wso2/siddhi/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/siddhi/statuses/48b76344362bcf6d9d502614b4a8c7d064df8464"}}}}