use of org.alfresco.service.cmr.dictionary.DictionaryException in project alfresco-remote-api by Alfresco.
the class AbstractRuleWebScript method convertValue.
private Serializable convertValue(QName typeQName, Object propertyValue) throws JSONException {
Serializable value = null;
DataTypeDefinition typeDef = dictionaryService.getDataType(typeQName);
if (typeDef == null) {
throw new AlfrescoRuntimeException("Action property type definition " + typeQName.toPrefixString() + " is unknown.");
}
if (propertyValue instanceof JSONArray) {
// Convert property type to java class
Class<?> javaClass = null;
String javaClassName = typeDef.getJavaClassName();
try {
javaClass = Class.forName(javaClassName);
} catch (ClassNotFoundException e) {
throw new DictionaryException("Java class " + javaClassName + " of property type " + typeDef.getName() + " is invalid", e);
}
int length = ((JSONArray) propertyValue).length();
List<Serializable> list = new ArrayList<Serializable>(length);
for (int i = 0; i < length; i++) {
list.add(convertValue(typeQName, ((JSONArray) propertyValue).get(i)));
}
value = (Serializable) list;
} else {
if (typeQName.equals(DataTypeDefinition.QNAME) == true && typeQName.toString().contains(":") == true) {
value = QName.createQName(propertyValue.toString(), namespaceService);
} else {
value = (Serializable) DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(typeQName), propertyValue);
}
}
return value;
}
use of org.alfresco.service.cmr.dictionary.DictionaryException 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.DictionaryException in project SearchServices by Alfresco.
the class AlfrescoSolrDataModel method validateModel.
private Set<String> validateModel(M2Model model) {
HashSet<String> errors = new HashSet<String>();
try {
dictionaryDAO.getCompiledModel(QName.createQName(model.getName(), namespaceDAO));
} catch (DictionaryException e) {
// No model to diff
return errors;
} catch (NamespaceException e) {
// namespace unknown - no model
return errors;
}
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModelIgnoringConstraints(model);
for (M2ModelDiff modelDiff : modelDiffs) {
if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_UPDATED)) {
errors.add("Model not updated: " + model.getName() + " Failed to validate model update - found non-incrementally updated " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
}
}
return errors;
}
use of org.alfresco.service.cmr.dictionary.DictionaryException in project alfresco-remote-api by Alfresco.
the class ActionsImpl method convertValue.
private Serializable convertValue(QName typeQName, Object propertyValue) throws JSONException {
Serializable value;
DataTypeDefinition typeDef = dictionaryService.getDataType(typeQName);
if (typeDef == null) {
throw new AlfrescoRuntimeException("Action property type definition " + typeQName.toPrefixString() + " is unknown.");
}
if (propertyValue instanceof JSONArray) {
// Convert property type to java class
String javaClassName = typeDef.getJavaClassName();
try {
Class.forName(javaClassName);
} catch (ClassNotFoundException e) {
throw new DictionaryException("Java class " + javaClassName + " of property type " + typeDef.getName() + " is invalid", e);
}
int length = ((JSONArray) propertyValue).length();
List<Serializable> list = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
list.add(convertValue(typeQName, ((JSONArray) propertyValue).get(i)));
}
value = (Serializable) list;
} else {
if (typeQName.equals(DataTypeDefinition.QNAME) && typeQName.toString().contains(":")) {
value = QName.createQName(propertyValue.toString(), namespaceService);
} else {
value = (Serializable) DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(typeQName), propertyValue);
}
}
return value;
}
use of org.alfresco.service.cmr.dictionary.DictionaryException in project alfresco-remote-api by Alfresco.
the class CustomModelUploadPost method processUpload.
protected ImportResult processUpload(ZipFile zipFile, String filename) throws IOException {
if (zipFile.size() > 2) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_package");
}
CustomModel customModel = null;
String shareExtModule = null;
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
final String entryName = entry.getName();
try (InputStream input = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE)) {
if (!(entryName.endsWith(CustomModelServiceImpl.SHARE_EXT_MODULE_SUFFIX)) && customModel == null) {
try {
M2Model m2Model = M2Model.createModel(input);
customModel = importModel(m2Model);
} catch (DictionaryException ex) {
if (shareExtModule == null) {
// Get the input stream again, as the zip file doesn't support reset.
try (InputStream moduleInputStream = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE)) {
shareExtModule = getExtensionModule(moduleInputStream, entryName);
}
if (shareExtModule == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_entry_format", new Object[] { entryName });
}
} else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_model_entry", new Object[] { entryName });
}
}
} else {
shareExtModule = getExtensionModule(input, entryName);
if (shareExtModule == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { entryName });
}
}
}
}
}
return new ImportResult(customModel, shareExtModule);
}
Aggregations