use of org.alfresco.service.cmr.dictionary.ClassDefinition in project records-management by Alfresco.
the class RecordServiceImpl method isRecordMetadataProperty.
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#isRecordMetadataProperty(org.alfresco.service.namespace.QName)
*/
@Override
public boolean isRecordMetadataProperty(QName property) {
boolean result = false;
PropertyDefinition propertyDefinition = dictionaryService.getProperty(property);
if (propertyDefinition != null) {
ClassDefinition classDefinition = propertyDefinition.getContainerClass();
if (classDefinition != null && getRecordMetadataAspectsMap().containsKey(classDefinition.getName())) {
result = true;
}
}
return result;
}
use of org.alfresco.service.cmr.dictionary.ClassDefinition in project records-management by Alfresco.
the class RecordServiceImpl method isRecordMetadata.
/**
* Helper method that indicates whether a property is considered record metadata or not.
*
* @param property property
* @return boolea true if record metadata, false otherwise
*/
private boolean isRecordMetadata(NodeRef filePlan, QName property) {
boolean result = false;
// grab the information about the properties parent type
ClassDefinition parent = null;
PropertyDefinition def = dictionaryService.getProperty(property);
if (def != null) {
parent = def.getContainerClass();
}
// TODO move non-electronic record support to a separate model namespace
if (parent != null && TYPE_NON_ELECTRONIC_DOCUMENT.equals(parent.getName())) {
result = false;
} else {
// check the URI's
result = RECORD_MODEL_URIS.contains(property.getNamespaceURI());
// check the custom model
if (!result && !ArrayUtils.contains(NON_RECORD_MODEL_URIS, property.getNamespaceURI())) {
if (parent != null && parent.isAspect()) {
result = getRecordMetadataAspects(filePlan).contains(parent.getName());
}
}
}
return result;
}
use of org.alfresco.service.cmr.dictionary.ClassDefinition in project records-management by Alfresco.
the class NodeParameterProcessor method getSubstitutionSuggestions.
/**
* Get a list of node substitution suggestions for the given definition and specified fragment.
*
* @param definitionName Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean getSubstitutionSuggestions(QName definitionName, String substitutionFragment, Set<String> suggestions) {
boolean gotMaximumSuggestions = false;
ClassDefinition definition = this.dictionaryService.getAspect(definitionName);
if (definition == null) {
definition = this.dictionaryService.getType(definitionName);
}
if (definition != null) {
gotMaximumSuggestions = getSubstitutionSuggestionsForDefinition(definition, substitutionFragment, suggestions);
}
if (recordsManagementAdminService.isCustomisable(definitionName) && !gotMaximumSuggestions) {
gotMaximumSuggestions = processPropertyDefinitions(recordsManagementAdminService.getCustomPropertyDefinitions(definitionName), substitutionFragment, suggestions);
}
return gotMaximumSuggestions;
}
use of org.alfresco.service.cmr.dictionary.ClassDefinition in project records-management by Alfresco.
the class RmClassesGet method executeImpl.
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, boolean isRM) {
String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
String className = null;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
List<QName> qnames = new ArrayList<QName>();
QName classQname = null;
QName myModel = null;
// if classfilter is not given, then it defaults to all
if (classFilter == null) {
classFilter = "all";
}
// validate classfilter
if (!isValidClassFilter(classFilter)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
}
// name alone has no meaning without namespaceprefix
if (namespacePrefix == null && name != null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
// validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if (namespacePrefix != null) {
// validate name parameter if present along with the namespaceprefix
if (name != null) {
className = namespacePrefix + "_" + name;
if (!isValidClassname(className)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
}
classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
} else {
// if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for (QName qnameObj : this.dictionaryservice.getAllModels()) {
if (qnameObj.getNamespaceURI().equals(namespaceUri)) {
name = qnameObj.getLocalName();
myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
// check the classfilter to pull out either all or type or aspects
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
qnames.addAll(this.dictionaryservice.getAspects(myModel));
qnames.addAll(this.dictionaryservice.getTypes(myModel));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
qnames.addAll(this.dictionaryservice.getTypes(myModel));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
qnames.addAll(this.dictionaryservice.getAspects(myModel));
}
}
}
}
}
// if namespacePrefix is null, then check the class filter to pull out either all, type or aspects
if (myModel == null) {
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
qnames.addAll(getAspects(isRM));
qnames.addAll(getTypes(isRM));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
qnames.addAll(getTypes(isRM));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
qnames.addAll(getAspects(isRM));
}
}
if (classdef.isEmpty()) {
for (QName qnameObj : qnames) {
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator(dictionaryservice));
model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
return model;
}
use of org.alfresco.service.cmr.dictionary.ClassDefinition in project SearchServices by Alfresco.
the class Solr4QueryParser method getFieldQuery.
/**
* @param field
* @param queryText
* @param analysisMode
* @param luceneFunction
* @return the query
* @throws ParseException
* @throws IOException
*/
@SuppressWarnings("deprecation")
public Query getFieldQuery(String field, String queryText, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
try {
if (field.equals(FIELD_PATH)) {
return createPathQuery(queryText, false);
} else if (field.equals(FIELD_PATHWITHREPEATS)) {
return createPathQuery(queryText, true);
} else if (field.equals(FIELD_TEXT)) {
return createTextQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ID)) {
return createIdQuery(queryText);
} else if (field.equals(FIELD_SOLR4_ID)) {
return createSolr4IdQuery(queryText);
} else if (field.equals(FIELD_DBID)) {
return createDbidQuery(queryText);
} else if (field.equals(FIELD_ACLID)) {
return createAclIdQuery(queryText);
} else if (field.equals(FIELD_OWNER)) {
return createOwnerQuery(queryText);
} else if (field.equals(FIELD_OWNERSET)) {
return createOwnerSetQuery(queryText);
} else if (field.equals(FIELD_READER)) {
return createReaderQuery(queryText);
} else if (field.equals(FIELD_READERSET)) {
return createReaderSetQuery(queryText);
} else if (field.equals(FIELD_AUTHORITY)) {
return createAuthorityQuery(queryText);
} else if (field.equals(FIELD_AUTHORITYSET)) {
return createAuthoritySetQuery(queryText);
} else if (field.equals(FIELD_DENIED)) {
return createDeniedQuery(queryText);
} else if (field.equals(FIELD_DENYSET)) {
return createDenySetQuery(queryText);
} else if (field.equals(FIELD_ISROOT)) {
return createIsRootQuery(queryText);
} else if (field.equals(FIELD_ISCONTAINER)) {
return createIsContainerQuery(queryText);
} else if (field.equals(FIELD_ISNODE)) {
return createIsNodeQuery(queryText);
} else if (field.equals(FIELD_TX)) {
return createTransactionQuery(queryText);
} else if (field.equals(FIELD_INTXID)) {
return createInTxIdQuery(queryText);
} else if (field.equals(FIELD_INACLTXID)) {
return createInAclTxIdQuery(queryText);
} else if (field.equals(FIELD_PARENT)) {
return createParentQuery(queryText);
} else if (field.equals(FIELD_PRIMARYPARENT)) {
return createPrimaryParentQuery(queryText);
} else if (field.equals(FIELD_QNAME)) {
return createQNameQuery(queryText);
} else if (field.equals(FIELD_PRIMARYASSOCQNAME)) {
return createPrimaryAssocQNameQuery(queryText);
} else if (field.equals(FIELD_PRIMARYASSOCTYPEQNAME)) {
return createPrimaryAssocTypeQNameQuery(queryText);
} else if (field.equals(FIELD_ASSOCTYPEQNAME)) {
return createAssocTypeQNameQuery(queryText);
} else if (field.equals(FIELD_CLASS)) {
ClassDefinition target = QueryParserUtils.matchClassDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, queryText);
if (target == null) {
return new TermQuery(new Term(FIELD_TYPE, "_unknown_"));
}
return getFieldQuery(target.isAspect() ? FIELD_ASPECT : FIELD_TYPE, queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_TYPE)) {
return createTypeQuery(queryText, false);
} else if (field.equals(FIELD_EXACTTYPE)) {
return createTypeQuery(queryText, true);
} else if (field.equals(FIELD_ASPECT)) {
return createAspectQuery(queryText, false);
} else if (field.equals(FIELD_EXACTASPECT)) {
return createAspectQuery(queryText, true);
} else if (isPropertyField(field)) {
Query query = attributeQueryBuilder(field, queryText, new FieldQuery(), analysisMode, luceneFunction);
return query;
} else if (field.equals(FIELD_ALL)) {
return createAllQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ISUNSET)) {
return createIsUnsetQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ISNULL)) {
return createIsNullQuery(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_ISNOTNULL)) {
return createIsNotNull(queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_EXISTS)) {
return createExistsQuery(queryText, analysisMode, luceneFunction);
} else if (QueryParserUtils.matchDataTypeDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, field) != null) {
return createDataTypeDefinitionQuery(field, queryText, analysisMode, luceneFunction);
} else if (field.equals(FIELD_FTSSTATUS)) {
return createTermQuery(field, queryText);
} else if (field.equals(FIELD_TXID)) {
return createTxIdQuery(queryText);
} else if (field.equals(FIELD_ACLTXID)) {
return createAclTxIdQuery(queryText);
} else if (field.equals(FIELD_TXCOMMITTIME)) {
return createTxCommitTimeQuery(queryText);
} else if (field.equals(FIELD_ACLTXCOMMITTIME)) {
return createAclTxCommitTimeQuery(queryText);
} else if (field.equals(FIELD_TAG)) {
return createTagQuery(queryText);
} else if (field.equals(FIELD_SITE)) {
return createSiteQuery(queryText);
} else if (field.equals(FIELD_PNAME)) {
return createPNameQuery(queryText);
} else if (field.equals(FIELD_NPATH)) {
return createNPathQuery(queryText);
} else if (field.equals(FIELD_TENANT)) {
return createTenantQuery(queryText);
} else if (field.equals(FIELD_ANCESTOR)) {
return createAncestorQuery(queryText);
} else if (field.equals(FIELD_FINGERPRINT)) {
String[] parts = queryText.split("_");
Collection values = null;
String nodeId = parts[0];
JSONObject json = (JSONObject) request.getContext().get(AbstractQParser.ALFRESCO_JSON);
String fingerPrint = null;
if (json != null) {
// Was the fingerprint passed in
String fingerPrintKey = "fingerprint." + nodeId;
if (json.has(fingerPrintKey)) {
fingerPrint = (String) json.get("fingerprint." + nodeId);
if (fingerPrint != null) {
List l = new ArrayList();
String[] hashes = fingerPrint.split(" ");
for (String hash : hashes) {
l.add(hash);
}
values = l;
}
}
} else {
json = new JSONObject();
}
// Is the fingerprint in the local SolrContentStore
if (values == null) {
long dbid = fetchDBID(nodeId);
if (dbid == -1 && isNumber(nodeId)) {
dbid = Long.parseLong(nodeId);
}
if (dbid > -1) {
SolrInputDocument solrDoc = solrContentStore.retrieveDocFromSolrContentStore(AlfrescoSolrDataModel.getTenantId(TenantService.DEFAULT_DOMAIN), dbid);
if (solrDoc != null) {
SolrInputField mh = solrDoc.getField("MINHASH");
if (mh != null) {
values = mh.getValues();
}
}
}
}
String shards = this.solrParams.get("shards");
if (values == null && shards != null) {
// we are in distributed mode
// Fetch the fingerPrint from the shards.
// The UUID and DBID will both work for method call.
values = fetchFingerPrint(shards, nodeId);
}
// If we're in distributed mode then add the fingerprint to the json
if (values != null && shards != null && fingerPrint == null) {
ModifiableSolrParams newParams = new ModifiableSolrParams();
newParams.add(solrParams);
solrParams = newParams;
json.put("fingerprint." + nodeId, join(values, " "));
String jsonString = json.toString();
newParams.add(AbstractQParser.ALFRESCO_JSON, jsonString);
request.getContext().put(AbstractQParser.ALFRESCO_JSON, json);
request.setParams(newParams);
}
return createFingerPrintQuery(field, queryText, values, analysisMode, luceneFunction);
} else {
return getFieldQueryImpl(field, queryText, analysisMode, luceneFunction);
}
} catch (SAXPathException e) {
throw new ParseException("Failed to parse XPath...\n" + e.getMessage());
} catch (IOException e) {
throw new ParseException("IO: " + e.getMessage());
}
}
Aggregations