]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
3c1b664243fa78af007ae6bf638e42e240a1ab1e
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.common.relation.nuxeo;
25
26 import java.lang.StringBuilder;
27
28 import org.collectionspace.services.client.IQueryManager;
29 import org.collectionspace.services.common.relation.RelationJAXBSchema;
30
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * RelationsUtils
36  *
37  * $LastChangedRevision: $
38  * $LastChangedDate: $
39  */
40 public class RelationsUtils {
41
42     /** The Constant logger. */
43     private static final Logger logger = LoggerFactory.getLogger(RelationsUtils.class);
44
45     /**
46      * Builds the where clause.
47      *
48      * @param subject the subject
49      * @param predicate the predicate
50      * @param object the object
51      * @return the string
52      */
53     public static String buildWhereClause(String subject, String subjectType,
54                 String predicate,
55                 String object, String objectType) {
56         String result = null;
57         
58         StringBuilder stringBuilder = new StringBuilder();
59         if (subject != null) {
60                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
61                                 RelationJAXBSchema.SUBJECT_CSID + " = " + "'" + subject + "'");
62         }
63         
64         if (subjectType != null) {
65                 if (stringBuilder.length() > 0) {
66                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
67                 }
68                 // BUG - this should use the new field RelationJAXBSchema.SUBJECT_DOCTYPE
69                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
70                                 RelationJAXBSchema.SUBJECT_DOCTYPE + " = " + "'" + subjectType + "'");
71         }
72         
73         if (predicate != null) {
74                 if (stringBuilder.length() > 0) {
75                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
76                 }
77                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
78                                 RelationJAXBSchema.RELATIONSHIP_TYPE + " = " + "'" + predicate + "'");
79         }
80         
81         if (object != null) {
82                 if (stringBuilder.length() > 0) {
83                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
84                 }
85                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
86                                 RelationJAXBSchema.OBJECT_CSID + " = " + "'" + object + "'");
87         }
88         
89         if (objectType != null) {
90                 if (stringBuilder.length() > 0) {
91                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
92                 }
93                 // BUG - this should use the new field RelationJAXBSchema.OBJECT_DOCTYPE
94                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
95                                 RelationJAXBSchema.OBJECT_DOCTYPE + " = " + "'" + objectType + "'");
96         }
97         
98         if (stringBuilder.length() > 0) {
99                 result = stringBuilder.toString();
100         }
101         
102         return result;
103     }
104 }
105