]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
cb974e88f5d4d9d5f9e50fcafa866c2d95f42744
[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 subjectOrObject) {
57         String result = null;
58         
59         StringBuilder stringBuilder = new StringBuilder();      
60         
61         if (subject != null) {
62                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
63                                 RelationJAXBSchema.SUBJECT_CSID + " = " + "'" + subject + "'");
64         }
65         
66         // (subectCsid = ${csid} OR objectCsid = ${csid})
67         if (subjectOrObject != null) {
68                 if (stringBuilder.length() > 0) {
69                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
70                 }
71                 stringBuilder.append("(" + RelationConstants.NUXEO_SCHEMA_NAME + ":" +
72                                 RelationJAXBSchema.SUBJECT_CSID + " = " + "'" + subjectOrObject + "'");
73                 stringBuilder.append(" OR " + RelationConstants.NUXEO_SCHEMA_NAME + ":" +
74                                 RelationJAXBSchema.OBJECT_CSID + " = " + "'" + subjectOrObject + "'" + ")");
75         }       
76         
77         if (subjectType != null) {
78                 if (stringBuilder.length() > 0) {
79                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
80                 }
81                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
82                                 RelationJAXBSchema.SUBJECT_DOCTYPE + " = " + "'" + subjectType + "'");
83         }
84         
85         if (predicate != null) {
86                 if (stringBuilder.length() > 0) {
87                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
88                 }
89                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
90                                 RelationJAXBSchema.RELATIONSHIP_TYPE + " = " + "'" + predicate + "'");
91         }
92         
93         if (object != null) {
94                 if (stringBuilder.length() > 0) {
95                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
96                 }
97                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
98                                 RelationJAXBSchema.OBJECT_CSID + " = " + "'" + object + "'");
99         }
100         
101         if (objectType != null) {
102                 if (stringBuilder.length() > 0) {
103                         stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
104                 }
105                 // BUG - this should use the new field RelationJAXBSchema.OBJECT_DOCTYPE
106                 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
107                                 RelationJAXBSchema.OBJECT_DOCTYPE + " = " + "'" + objectType + "'");
108         }
109         
110         if (stringBuilder.length() > 0) {
111                 result = stringBuilder.toString();
112         }
113         
114         return result;
115     }
116 }
117