001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nicolas Ulrich
018 */
019package org.nuxeo.ecm.platform.task;
020
021import java.util.Iterator;
022import java.util.List;
023
024import org.nuxeo.ecm.core.query.sql.NXQL;
025
026/**
027 * @since 5.5
028 */
029public class TaskQueryConstant {
030
031    /**
032     * @deprecated since 6.0: use page providers instead.
033     */
034    @Deprecated
035    public static final String TASK_VARIABLES_WHERE_CLAUSE = "nt:task_variables/*/key = '%s' AND nt:task_variables/*/value = '%s'";
036
037    /**
038     * @deprecated since 6.0: use page providers instead.
039     */
040    @Deprecated
041    public static final String TASK_ACTORS_WHERE_CLAUSE = " nt:actors/* IN (%s) ";
042
043    /**
044     * @since 6.0
045     */
046    public static final String GET_TASKS_FOR_ACTORS_PP = "GET_TASKS_FOR_ACTORS";
047
048    /**
049     * @deprecated since 6.0: use page providers instead.
050     */
051    @Deprecated
052    public static final String GET_TASKS_QUERY = "SELECT * FROM Document WHERE ecm:mixinType = '"
053            + TaskConstants.TASK_FACET_NAME + "'" + " AND ecm:currentLifeCycleState NOT IN ('ended', 'cancelled')"
054            + " AND ecm:isProxy = 0";
055
056    /**
057     * @deprecated since 6.0: use page providers instead.
058     */
059    @Deprecated
060    public static final String GET_TASKS_FOR_ACTORS_QUERY = GET_TASKS_QUERY + " AND nt:actors/* IN (%s) ";
061
062    /**
063     * @since 6.0
064     */
065    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_PP = "GET_TASKS_FOR_TARGET_DOCUMENT";
066
067    /**
068     * @deprecated since 6.0: use page providers instead.
069     */
070    @Deprecated
071    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_QUERY = GET_TASKS_QUERY
072            + " AND nt:targetDocumentId = '%s'";
073
074    /**
075     * @since 6.0
076     */
077    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_PP = "GET_TASKS_FOR_TARGET_DOCUMENTS";
078
079    /**
080     * @since 5.8
081     * @deprecated since 6.0: use page providers instead.
082     */
083    @Deprecated
084    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_QUERY = GET_TASKS_QUERY
085            + " AND ( nt:targetDocumentId = '%s' OR nt:targetDocumentsIds/* IN ('%s') )";
086
087    /**
088     * @since 6.0
089     */
090    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_PP = "GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS";
091
092    /**
093     * @deprecated since 6.0: use page providers instead.
094     */
095    @Deprecated
096    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_QUERY = GET_TASKS_QUERY
097            + " AND nt:targetDocumentId = '%s' AND nt:actors/* IN (%s) ";
098
099    /**
100     * @since 6.0
101     */
102    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS_PP = "GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS";
103
104    /**
105     * @since 5.8
106     * @deprecated since 6.0: use page providers instead.
107     */
108    @Deprecated
109    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS_QUERY = GET_TASKS_QUERY
110            + " AND ( nt:targetDocumentId = '%s' OR nt:targetDocumentsIds/* IN ('%s') ) AND nt:actors/* IN (%s) ";
111
112    /**
113     * @since 6.0
114     */
115    public static final String GET_TASKS_FOR_PROCESS_PP = "GET_TASKS_FOR_PROCESS";
116
117    /**
118     * @since 5.6
119     * @deprecated since 6.0: use page providers instead.
120     */
121    @Deprecated
122    public static final String GET_TASKS_FOR_PROCESS_ID_QUERY = GET_TASKS_QUERY + " AND nt:processId = '%s' ";
123
124    /**
125     * @since 6.0
126     */
127    public static final String GET_TASKS_FOR_PROCESS_AND_ACTORS_PP = "GET_TASKS_FOR_PROCESS_AND_ACTORS";
128
129    /**
130     * @since 5.6
131     * @deprecated since 6.0: use page providers instead.
132     */
133    @Deprecated
134    public static final String GET_TASKS_FOR_PROCESS_ID_AND_ACTORS_QUERY = GET_TASKS_QUERY
135            + " AND nt:processId = '%s' AND nt:actors/* IN (%s) ";
136
137    /**
138     * @since 6.0
139     */
140    public static final String GET_TASKS_FOR_PROCESS_AND_NODE_PP = "GET_TASKS_FOR_PROCESS_AND_NODE";
141
142    /**
143     * @since 5.7
144     * @deprecated since 6.0: use page providers instead.
145     */
146    @Deprecated
147    public static final String GET_TASKS_FOR_PROCESS_ID_AND_NODE_ID_QUERY = GET_TASKS_FOR_PROCESS_ID_QUERY
148            + " AND nt:task_variables/*/key = 'nodeId' AND nt:task_variables/*/value =  '%s' ";
149
150    /**
151     * @since 6.0
152     */
153    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS_OR_DELEGATED_ACTORS_PP = "GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS_OR_DELEGATED_ACTORS";
154
155    /**
156     * @since 7.4
157     */
158    public static final String GET_TASKS_FOR_ACTORS_OR_DELEGATED_ACTORS_PP = "GET_TASKS_FOR_ACTORS_OR_DELEGATED_ACTORS";
159
160    /**
161     * @since 5.8
162     * @deprecated since 6.0: use page providers instead.
163     */
164    @Deprecated
165    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_QUERY_OR_DELEGATED_ACTORS_QUERY = GET_TASKS_QUERY
166            + " AND ( nt:targetDocumentId = '%s' OR nt:targetDocumentsIds/* IN ('%s') ) AND ( nt:actors/* IN (%s) OR nt:delegatedActors/* IN (%s) ) ";
167
168    /**
169     * @deprecated since 6.0: page providers implement this logic instead.
170     */
171    @Deprecated
172    public static String getVariableWhereClause(String key, String value) {
173        return String.format(TASK_VARIABLES_WHERE_CLAUSE, key, value);
174    }
175
176    /**
177     * @deprecated since 6.0: page providers implement this logic instead.
178     */
179    @Deprecated
180    public static String getActorsWhereClause(List<String> actors) {
181        return String.format(TASK_ACTORS_WHERE_CLAUSE, formatStringList(actors));
182    }
183
184    /**
185     * @deprecated since 6.0: page providers implement this logic instead.
186     */
187    @Deprecated
188    public static String formatStringList(List<String> actors) {
189        StringBuffer sb = new StringBuffer();
190        Iterator<String> actorIterator = actors.iterator();
191        while (actorIterator.hasNext()) {
192            String userName = actorIterator.next();
193            sb.append(NXQL.escapeString(userName));
194            if (actorIterator.hasNext()) {
195                sb.append(',');
196            }
197        }
198        return sb.toString();
199    }
200
201}