001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nicolas Ulrich
016 */
017package org.nuxeo.ecm.platform.task;
018
019import java.util.Iterator;
020import java.util.List;
021
022import org.nuxeo.ecm.core.query.sql.NXQL;
023
024/**
025 * @since 5.5
026 */
027public class TaskQueryConstant {
028
029    /**
030     * @deprecated since 6.0: use page providers instead.
031     */
032    @Deprecated
033    public static final String TASK_VARIABLES_WHERE_CLAUSE = "nt:task_variables/*/key = '%s' AND nt:task_variables/*/value = '%s'";
034
035    /**
036     * @deprecated since 6.0: use page providers instead.
037     */
038    @Deprecated
039    public static final String TASK_ACTORS_WHERE_CLAUSE = " nt:actors/* IN (%s) ";
040
041    /**
042     * @since 6.0
043     */
044    public static final String GET_TASKS_FOR_ACTORS_PP = "GET_TASKS_FOR_ACTORS";
045
046    /**
047     * @deprecated since 6.0: use page providers instead.
048     */
049    @Deprecated
050    public static final String GET_TASKS_QUERY = "SELECT * FROM Document WHERE ecm:mixinType = '"
051            + TaskConstants.TASK_FACET_NAME + "'" + " AND ecm:currentLifeCycleState NOT IN ('ended', 'cancelled')"
052            + " AND ecm:isProxy = 0";
053
054    /**
055     * @deprecated since 6.0: use page providers instead.
056     */
057    @Deprecated
058    public static final String GET_TASKS_FOR_ACTORS_QUERY = GET_TASKS_QUERY + " AND nt:actors/* IN (%s) ";
059
060    /**
061     * @since 6.0
062     */
063    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_PP = "GET_TASKS_FOR_TARGET_DOCUMENT";
064
065    /**
066     * @deprecated since 6.0: use page providers instead.
067     */
068    @Deprecated
069    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_QUERY = GET_TASKS_QUERY
070            + " AND nt:targetDocumentId = '%s'";
071
072    /**
073     * @since 6.0
074     */
075    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_PP = "GET_TASKS_FOR_TARGET_DOCUMENTS";
076
077    /**
078     * @since 5.8
079     * @deprecated since 6.0: use page providers instead.
080     */
081    @Deprecated
082    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_QUERY = GET_TASKS_QUERY
083            + " AND ( nt:targetDocumentId = '%s' OR nt:targetDocumentsIds/* IN ('%s') )";
084
085    /**
086     * @since 6.0
087     */
088    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_PP = "GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS";
089
090    /**
091     * @deprecated since 6.0: use page providers instead.
092     */
093    @Deprecated
094    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_QUERY = GET_TASKS_QUERY
095            + " AND nt:targetDocumentId = '%s' AND nt:actors/* IN (%s) ";
096
097    /**
098     * @since 6.0
099     */
100    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS_PP = "GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS";
101
102    /**
103     * @since 5.8
104     * @deprecated since 6.0: use page providers instead.
105     */
106    @Deprecated
107    public static final String GET_TASKS_FOR_TARGET_DOCUMENTS_AND_ACTORS_QUERY = GET_TASKS_QUERY
108            + " AND ( nt:targetDocumentId = '%s' OR nt:targetDocumentsIds/* IN ('%s') ) AND nt:actors/* IN (%s) ";
109
110    /**
111     * @since 6.0
112     */
113    public static final String GET_TASKS_FOR_PROCESS_PP = "GET_TASKS_FOR_PROCESS";
114
115    /**
116     * @since 5.6
117     * @deprecated since 6.0: use page providers instead.
118     */
119    @Deprecated
120    public static final String GET_TASKS_FOR_PROCESS_ID_QUERY = GET_TASKS_QUERY + " AND nt:processId = '%s' ";
121
122    /**
123     * @since 6.0
124     */
125    public static final String GET_TASKS_FOR_PROCESS_AND_ACTORS_PP = "GET_TASKS_FOR_PROCESS_AND_ACTORS";
126
127    /**
128     * @since 5.6
129     * @deprecated since 6.0: use page providers instead.
130     */
131    @Deprecated
132    public static final String GET_TASKS_FOR_PROCESS_ID_AND_ACTORS_QUERY = GET_TASKS_QUERY
133            + " AND nt:processId = '%s' AND nt:actors/* IN (%s) ";
134
135    /**
136     * @since 6.0
137     */
138    public static final String GET_TASKS_FOR_PROCESS_AND_NODE_PP = "GET_TASKS_FOR_PROCESS_AND_NODE";
139
140    /**
141     * @since 5.7
142     * @deprecated since 6.0: use page providers instead.
143     */
144    @Deprecated
145    public static final String GET_TASKS_FOR_PROCESS_ID_AND_NODE_ID_QUERY = GET_TASKS_FOR_PROCESS_ID_QUERY
146            + " AND nt:task_variables/*/key = 'nodeId' AND nt:task_variables/*/value =  '%s' ";
147
148    /**
149     * @since 6.0
150     */
151    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";
152
153    /**
154     * @since 7.4
155     */
156    public static final String GET_TASKS_FOR_ACTORS_OR_DELEGATED_ACTORS_PP = "GET_TASKS_FOR_ACTORS_OR_DELEGATED_ACTORS";
157
158    /**
159     * @since 5.8
160     * @deprecated since 6.0: use page providers instead.
161     */
162    @Deprecated
163    public static final String GET_TASKS_FOR_TARGET_DOCUMENT_AND_ACTORS_QUERY_OR_DELEGATED_ACTORS_QUERY = GET_TASKS_QUERY
164            + " AND ( nt:targetDocumentId = '%s' OR nt:targetDocumentsIds/* IN ('%s') ) AND ( nt:actors/* IN (%s) OR nt:delegatedActors/* IN (%s) ) ";
165
166    /**
167     * @deprecated since 6.0: page providers implement this logic instead.
168     */
169    @Deprecated
170    public static String getVariableWhereClause(String key, String value) {
171        return String.format(TASK_VARIABLES_WHERE_CLAUSE, key, value);
172    }
173
174    /**
175     * @deprecated since 6.0: page providers implement this logic instead.
176     */
177    @Deprecated
178    public static String getActorsWhereClause(List<String> actors) {
179        return String.format(TASK_ACTORS_WHERE_CLAUSE, formatStringList(actors));
180    }
181
182    /**
183     * @deprecated since 6.0: page providers implement this logic instead.
184     */
185    @Deprecated
186    public static String formatStringList(List<String> actors) {
187        StringBuffer sb = new StringBuffer();
188        Iterator<String> actorIterator = actors.iterator();
189        while (actorIterator.hasNext()) {
190            String userName = actorIterator.next();
191            sb.append(NXQL.escapeString(userName));
192            if (actorIterator.hasNext()) {
193                sb.append(',');
194            }
195        }
196        return sb.toString();
197    }
198
199}