use of org.alfresco.service.cmr.dictionary.AspectDefinition in project acs-community-packaging by Alfresco.
the class UISearchCustomProperties method createComponentsFromConfig.
/**
* Build the components from the Advanced Search config entries
*
* @param context FacesContext
*/
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context) {
DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
AdvancedSearchConfigElement config = (AdvancedSearchConfigElement) Application.getConfigService(context).getConfig("Advanced Search").getConfigElement(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID);
// create an appropriate component for each custom property
// using the DataDictionary to look-up labels and value types
String beanBinding = (String) getAttributes().get("bean") + '.' + (String) getAttributes().get("var");
List<CustomProperty> props = config.getCustomProperties();
if (props != null) {
for (CustomProperty property : props) {
try {
// try to find the Property definition for the specified Type or Aspect
PropertyDefinition propDef = null;
if (property.Type != null) {
QName type = Repository.resolveToQName(property.Type);
TypeDefinition typeDef = dd.getType(type);
if (typeDef == null) {
logger.warn("No Type Definition found for: " + property.Type + " - Was an Aspect expected?");
continue;
}
propDef = typeDef.getProperties().get(Repository.resolveToQName(property.Property));
} else if (property.Aspect != null) {
QName aspect = Repository.resolveToQName(property.Aspect);
AspectDefinition aspectDef = dd.getAspect(aspect);
if (aspectDef == null) {
logger.warn("No Aspect Definition found for: " + property.Aspect + " - Was a Type expected?");
continue;
}
propDef = aspectDef.getProperties().get(Repository.resolveToQName(property.Property));
}
// if we found a def, then we can build components to represent it
if (propDef != null) {
// resolve display label I18N message
String label;
if (property.LabelId != null && property.LabelId.length() != 0) {
label = Application.getMessage(context, property.LabelId);
} else {
// or use dictionary label or QName as last resort
label = propDef.getTitle(dd) != null ? propDef.getTitle(dd) : propDef.getName().getLocalName();
}
// special handling for Date and DateTime
DataTypeDefinition dataTypeDef = propDef.getDataType();
if (DataTypeDefinition.DATE.equals(dataTypeDef.getName()) || DataTypeDefinition.DATETIME.equals(dataTypeDef.getName())) {
getChildren().add(generateControl(context, propDef, label, beanBinding));
} else {
// add ListOfValues constraint components
ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
if (constraint != null && propDef != null && propDef.isProtected() == false) {
getChildren().add(generateCheck(context, propDef, beanBinding));
getChildren().add(generateLabel(context, label + ": "));
} else {
getChildren().add(generateLabel(context, ""));
getChildren().add(generateLabel(context, label + ": "));
}
getChildren().add(generateControl(context, propDef, null, beanBinding));
}
}
} catch (DictionaryException ddErr) {
logger.warn("Error building custom properties for Advanced Search: " + ddErr.getMessage());
}
}
}
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition in project acs-community-packaging by Alfresco.
the class TransientNode method createNew.
/**
* Construct a transient node for an item yet to be created in the Repository.
*
* This will apply any one-time initialisation required upon creation of the node
* e.g. assignment of default values.
*
* @param dictionaryService dictionary service
* @param typeDef The type definition this node will represent
* @param name The name of the node
* @param data The properties and associations this node will have
* @return transient node
*/
public static TransientNode createNew(DictionaryService dictionaryService, TypeDefinition typeDef, String name, Map<QName, Serializable> data) {
// build a complete anonymous type for the start task
List<AspectDefinition> aspects = typeDef.getDefaultAspects();
List<QName> aspectNames = new ArrayList<QName>(aspects.size());
getMandatoryAspects(typeDef, aspectNames);
ClassDefinition startTaskDef = dictionaryService.getAnonymousType(typeDef.getName(), aspectNames);
// initialise start task values
Map<QName, Serializable> startValues = new HashMap<QName, Serializable>();
if (data != null) {
startValues.putAll(data);
}
// apply default values
Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties();
for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet()) {
String defaultValue = entry.getValue().getDefaultValue();
if (defaultValue != null) {
if (startValues.get(entry.getKey()) == null) {
startValues.put(entry.getKey(), (Serializable) DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), defaultValue));
}
}
}
return new TransientNode(typeDef.getName(), name, startValues);
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition in project acs-community-packaging by Alfresco.
the class TransientNode method getMandatoryAspects.
/**
* Gets a flattened list of all mandatory aspects for a given class
*
* @param classDef the class
* @param aspects a list to hold the mandatory aspects
*/
private static void getMandatoryAspects(ClassDefinition classDef, List<QName> aspects) {
for (AspectDefinition aspect : classDef.getDefaultAspects()) {
QName aspectName = aspect.getName();
if (!aspects.contains(aspectName)) {
aspects.add(aspect.getName());
getMandatoryAspects(aspect, aspects);
}
}
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition in project SearchServices by Alfresco.
the class Solr4QueryParser method createAspectQuery.
protected Query createAspectQuery(String queryText, boolean exactOnly) {
AspectDefinition target = QueryParserUtils.matchAspectDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, queryText);
if (target == null) {
return new TermQuery(new Term(FIELD_ASPECT, "_unknown_"));
}
if (exactOnly) {
QName targetQName = target.getName();
TermQuery termQuery = new TermQuery(new Term(FIELD_ASPECT, targetQName.toString()));
return termQuery;
} else {
Collection<QName> subclasses = dictionaryService.getSubAspects(target.getName(), true);
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
for (QName qname : subclasses) {
AspectDefinition current = dictionaryService.getAspect(qname);
if (target.getName().equals(current.getName()) || current.getIncludedInSuperTypeQuery()) {
TermQuery termQuery = new TermQuery(new Term(FIELD_ASPECT, qname.toString()));
if (termQuery != null) {
booleanQuery.add(termQuery, Occur.SHOULD);
}
}
}
return booleanQuery.build();
}
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.
the class RecordsManagementAdminBase method getCustomAssociations.
/**
* Gets all the custom associations
*
* @return All custom associations
*/
protected Map<QName, AssociationDefinition> getCustomAssociations() {
Map<QName, AssociationDefinition> customAssociations = new HashMap<QName, AssociationDefinition>();
AspectDefinition aspectDefn = getDictionaryService().getAspect(ASPECT_CUSTOM_ASSOCIATIONS);
if (aspectDefn != null) {
customAssociations.putAll(aspectDefn.getAssociations());
}
return customAssociations;
}
Aggregations