use of org.alfresco.service.namespace.NamespaceException in project alfresco-repository by Alfresco.
the class TypeVirtualizationMethodUnitTest method mockNamespacePrefixResolver.
static NamespacePrefixResolver mockNamespacePrefixResolver() {
NamespacePrefixResolver mockNamespacePrefixResolver = Mockito.mock(NamespacePrefixResolver.class, new ThrowsException(new NamespaceException("Mock exception ")));
Mockito.doReturn(Arrays.<String>asList(SiteModel.SITE_MODEL_PREFIX)).when(mockNamespacePrefixResolver).getPrefixes(SiteModel.SITE_MODEL_URL);
Mockito.doReturn(SiteModel.SITE_MODEL_URL).when(mockNamespacePrefixResolver).getNamespaceURI(SiteModel.SITE_MODEL_PREFIX);
Mockito.doReturn(Arrays.<String>asList(NamespaceService.CONTENT_MODEL_PREFIX)).when(mockNamespacePrefixResolver).getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI);
Mockito.doReturn(NamespaceService.CONTENT_MODEL_1_0_URI).when(mockNamespacePrefixResolver).getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX);
Mockito.doReturn("mock(NamespacePrefixResolver)@" + TypeVirtualizationMethod.class.toString()).when(mockNamespacePrefixResolver).toString();
return mockNamespacePrefixResolver;
}
use of org.alfresco.service.namespace.NamespaceException 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.namespace.NamespaceException in project alfresco-repository by Alfresco.
the class JSONConversionComponent method propertiesToJSON.
/**
* @param nodeRef NodeRef
* @param useShortQNames boolean
* @return JSONObject
*/
@SuppressWarnings("unchecked")
protected JSONObject propertiesToJSON(NodeRef nodeRef, Map<QName, Serializable> properties, boolean useShortQNames) {
JSONObject propertiesJSON = new JSONObject();
for (QName propertyName : properties.keySet()) {
try {
String key = nameToString(propertyName, useShortQNames);
Serializable value = properties.get(propertyName);
propertiesJSON.put(key, propertyToJSON(nodeRef, propertyName, key, value));
} catch (NamespaceException ne) {
// ignore properties that do not have a registered namespace
if (logger.isDebugEnabled())
logger.debug("Ignoring property '" + propertyName + "' as its namespace is not registered");
}
}
return propertiesJSON;
}
use of org.alfresco.service.namespace.NamespaceException in project alfresco-repository by Alfresco.
the class ScriptNode method toJSON.
/**
* Returns the JSON representation of this node.
*
* @param useShortQNames if true short-form qnames will be returned, else long-form.
* @return The JSON representation of this node
*/
public String toJSON(boolean useShortQNames) {
// This method is used by the /api/metadata web script
String jsonStr = "{}";
if (this.nodeService.exists(nodeRef)) {
if (this.services.getPublicServiceAccessService().hasAccess(ServiceRegistry.NODE_SERVICE.getLocalName(), "getProperties", this.nodeRef) == AccessStatus.ALLOWED) {
JSONObject json = new JSONObject();
try {
// add type info
json.put("nodeRef", this.getNodeRef().toString());
String typeString = useShortQNames ? getShortQName(this.getQNameType()) : this.getType();
json.put("type", typeString);
json.put("mimetype", this.getMimetype());
// Fetch all properties
Map<QName, Serializable> nodeProperties = this.nodeService.getProperties(this.nodeRef);
// Do any special conversion steps that are needed
for (QName longQName : nodeProperties.keySet()) {
Serializable value = nodeProperties.get(longQName);
if (value instanceof Date) {
value = ISO8601DateFormat.format((Date) value);
nodeProperties.put(longQName, value);
}
if (value instanceof NodeRef) {
value = ((NodeRef) value).toString();
nodeProperties.put(longQName, value);
}
}
if (useShortQNames) {
Map<String, Serializable> nodePropertiesShortQNames = new LinkedHashMap<String, Serializable>(nodeProperties.size());
for (QName nextLongQName : nodeProperties.keySet()) {
try {
String nextShortQName = getShortQName(nextLongQName);
nodePropertiesShortQNames.put(nextShortQName, nodeProperties.get(nextLongQName));
} catch (NamespaceException ne) {
if (logger.isDebugEnabled())
logger.debug("Ignoring property '" + nextLongQName + "' as it's namespace is not registered");
}
}
json.put("properties", nodePropertiesShortQNames);
} else {
json.put("properties", nodeProperties);
}
// add aspects as an array
Set<QName> nodeAspects = this.nodeService.getAspects(this.nodeRef);
if (useShortQNames) {
Set<String> nodeAspectsShortQNames = new LinkedHashSet<String>(nodeAspects.size());
for (QName nextLongQName : nodeAspects) {
String nextShortQName = getShortQName(nextLongQName);
nodeAspectsShortQNames.add(nextShortQName);
}
json.put("aspects", nodeAspectsShortQNames);
} else {
json.put("aspects", nodeAspects);
}
} catch (JSONException error) {
error.printStackTrace();
}
jsonStr = json.toString();
}
}
return jsonStr;
}
use of org.alfresco.service.namespace.NamespaceException in project alfresco-repository by Alfresco.
the class QNameFieldProcessor method generateTypedField.
/* (non-Javadoc)
* @see org.alfresco.repo.forms.field.processor.AbstractFieldProcessor#generateTypedField(java.lang.String, java.lang.Object)
*/
@Override
protected Field generateTypedField(String fieldName, FormCreationData formData, ContentModelItemData<?> typedData) {
Field field = null;
try {
QName fullName = getFullName(fieldName);
boolean isForcedField = formData.isForcedField(fieldName);
field = generateField(fullName, typedData, isForcedField);
} catch (NamespaceException ne) {
// ignore fields with an invalid namespace - the model may no longer be present in the repository
}
return field;
}
Aggregations