Search in sources :

Example 6 with NamespaceException

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;
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) NamespaceException(org.alfresco.service.namespace.NamespaceException) NamespacePrefixResolver(org.alfresco.service.namespace.NamespacePrefixResolver)

Example 7 with NamespaceException

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;
}
Also used : NamespaceException(org.alfresco.service.namespace.NamespaceException) M2ModelDiff(org.alfresco.repo.dictionary.M2ModelDiff) HashSet(java.util.HashSet) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 8 with NamespaceException

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;
}
Also used : Serializable(java.io.Serializable) JSONObject(org.json.simple.JSONObject) QName(org.alfresco.service.namespace.QName) NamespaceException(org.alfresco.service.namespace.NamespaceException)

Example 9 with NamespaceException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) JSONException(org.json.JSONException) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) NamespaceException(org.alfresco.service.namespace.NamespaceException)

Example 10 with NamespaceException

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;
}
Also used : Field(org.alfresco.repo.forms.Field) QName(org.alfresco.service.namespace.QName) NamespaceException(org.alfresco.service.namespace.NamespaceException)

Aggregations

NamespaceException (org.alfresco.service.namespace.NamespaceException)13 QName (org.alfresco.service.namespace.QName)9 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 JSONException (org.json.JSONException)2 Collection (java.util.Collection)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 M2ModelDiff (org.alfresco.repo.dictionary.M2ModelDiff)1 ActivityFeedEntity (org.alfresco.repo.domain.activities.ActivityFeedEntity)1 Field (org.alfresco.repo.forms.Field)1 FieldData (org.alfresco.repo.forms.FormData.FieldData)1 SyntheticPropertyDefinition (org.alfresco.repo.search.impl.solr.facet.SolrFacetService.SyntheticPropertyDefinition)1