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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.common.relation.nuxeo;
26 import java.lang.StringBuilder;
28 import org.collectionspace.services.client.IQueryManager;
29 import org.collectionspace.services.common.relation.RelationJAXBSchema;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
37 * $LastChangedRevision: $
40 public class RelationsUtils {
42 /** The Constant logger. */
43 private static final Logger logger = LoggerFactory.getLogger(RelationsUtils.class);
46 * Builds the where clause.
48 * @param subject the subject
49 * @param predicate the predicate
50 * @param object the object
53 public static String buildWhereClause(String subject, String subjectType,
55 String object, String objectType) {
58 StringBuilder stringBuilder = new StringBuilder();
59 if (subject != null) {
60 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
61 RelationJAXBSchema.DOCUMENT_ID_1 + " = " + "'" + subject + "'");
64 if (subjectType != null) {
65 if (stringBuilder.length() > 0) {
66 stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
68 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
69 RelationJAXBSchema.DOCUMENT_TYPE_1 + " = " + "'" + subjectType + "'");
72 if (predicate != null) {
73 if (stringBuilder.length() > 0) {
74 stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
76 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
77 RelationJAXBSchema.RELATIONSHIP_TYPE + " = " + "'" + predicate + "'");
81 if (stringBuilder.length() > 0) {
82 stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
84 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
85 RelationJAXBSchema.DOCUMENT_ID_2 + " = " + "'" + object + "'");
88 if (objectType != null) {
89 if (stringBuilder.length() > 0) {
90 stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
92 stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
93 RelationJAXBSchema.DOCUMENT_TYPE_2 + " = " + "'" + objectType + "'");
96 if (stringBuilder.length() > 0) {
97 result = stringBuilder.toString();