Search in sources :

Example 1 with NamespaceException

use of org.alfresco.service.namespace.NamespaceException in project alfresco-remote-api by Alfresco.

the class FacetablePropertiesGet method unprotectedExecuteImpl.

@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) {
    // We use any provided locale to localise some elements of the webscript response, but not all.
    final String userLocaleString = req.getParameter(QUERY_PARAM_LOCALE);
    final Locale userLocale = (userLocaleString == null) ? Locale.getDefault() : new Locale(userLocaleString);
    // There are multiple defined URIs for this REST endpoint. Some define a "classname" template var.
    final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    final String contentClassName = templateVars.get(TEMPLATE_VAR_CLASSNAME);
    final QName contentClassQName;
    try {
        contentClassQName = contentClassName == null ? null : QName.createQName(contentClassName, namespaceService);
    } catch (NamespaceException e) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unrecognised classname: " + contentClassName, e);
    }
    // Build an FTL model of facetable properties - this includes normal Alfresco properties and also
    // 'synthetic' properties like size and mimetype. See below for more details.
    final Map<String, Object> model = new HashMap<>();
    final SortedSet<FacetablePropertyFTL<?>> facetableProperties;
    if (contentClassQName == null) {
        facetableProperties = toFacetablePropertyModel(facetService.getFacetableProperties(), userLocale);
        final List<SyntheticPropertyDefinition> facetableSyntheticProperties = facetService.getFacetableSyntheticProperties();
        facetableProperties.addAll(toFacetablePropertyModel_(facetableSyntheticProperties, userLocale));
    } else {
        facetableProperties = toFacetablePropertyModel(facetService.getFacetableProperties(contentClassQName), userLocale);
        final List<SyntheticPropertyDefinition> facetableSyntheticProperties = facetService.getFacetableSyntheticProperties(contentClassQName);
        facetableProperties.addAll(toFacetablePropertyModel_(facetableSyntheticProperties, userLocale));
    }
    // Always add some hard-coded facetable "properties"
    // Note: TAG and SITE are Solr specials and don’t have namespaces
    facetableProperties.add(new SpecialFacetablePropertyFTL("TAG", "Tag"));
    facetableProperties.add(new SpecialFacetablePropertyFTL("SITE", "Site"));
    // The webscript allows for some further filtering of results:
    List<ResultFilter> filters = new ArrayList<>();
    // Filter by property QName namespace:
    final String namespaceFilter = req.getParameter(QUERY_PARAM_NAMESPACE);
    if (namespaceFilter != null) {
        filters.add(new ResultFilter() {

            @Override
            public boolean filter(FacetablePropertyFTL<?> facetableProperty) {
                final QName propQName = facetableProperty.getQname();
                Collection<String> prefixes = namespaceService.getPrefixes(propQName.getNamespaceURI());
                return prefixes.contains(namespaceFilter);
            }
        });
    }
    List<FacetablePropertyFTL<?>> filteredFacetableProperties = filter(facetableProperties, filters);
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved " + facetableProperties.size() + " available facets; filtered to " + filteredFacetableProperties.size());
    }
    // Create paging
    ScriptPagingDetails paging = new ScriptPagingDetails(getNonNegativeIntParameter(req, QUERY_PARAM_MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE), getNonNegativeIntParameter(req, QUERY_PARAM_SKIP_COUNT, 0));
    model.put(PROPERTIES_KEY, ModelUtil.page(filteredFacetableProperties, paging));
    model.put("paging", ModelUtil.buildPaging(paging));
    return model;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) SpecialFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL) StandardFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.StandardFacetablePropertyFTL) SyntheticFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SyntheticFacetablePropertyFTL) SpecialFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) SyntheticPropertyDefinition(org.alfresco.repo.search.impl.solr.facet.SolrFacetService.SyntheticPropertyDefinition) NamespaceException(org.alfresco.service.namespace.NamespaceException) Collection(java.util.Collection) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Example 2 with NamespaceException

use of org.alfresco.service.namespace.NamespaceException in project alfresco-repository by Alfresco.

the class AbstractUserNotifier method notifyUser.

public Pair<Integer, Long> notifyUser(final NodeRef personNodeRef, String subject, Object[] subjectParams, Map<String, String> siteNames, String shareUrl, int repeatIntervalMins, String templateNodeRef) {
    Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
    String feedUserId = (String) personProps.get(ContentModel.PROP_USERNAME);
    if (skipUser(personNodeRef)) {
        // skip
        return null;
    }
    // where did we get up to ?
    Long feedDBID = getFeedId(personNodeRef);
    // own + others (note: template can be changed to filter out user's own activities if needed)
    if (logger.isDebugEnabled()) {
        logger.debug("Get user feed entries: " + feedUserId + ", " + feedDBID);
    }
    List<ActivityFeedEntity> feedEntries = activityService.getUserFeedEntries(feedUserId, null, false, false, null, null, feedDBID);
    if (feedEntries.size() > 0) {
        ActivitiesFeedModelBuilder modelBuilder;
        try {
            modelBuilder = activitiesFeedModelBuilderFactory.getObject();
        } catch (Exception error) {
            logger.warn("Unable to create model builder: " + error.getMessage());
            return null;
        }
        for (ActivityFeedEntity feedEntry : feedEntries) {
            try {
                modelBuilder.addActivityFeedEntry(feedEntry);
                String siteId = feedEntry.getSiteNetwork();
                addSiteName(siteId, siteNames);
            } catch (JSONException je) {
                // skip this feed entry
                logger.warn("Skip feed entry for user (" + feedUserId + "): " + je.getMessage());
                continue;
            }
        }
        final int activityCount = modelBuilder.activityCount();
        if (activityCount > 0) {
            Map<String, Object> model = modelBuilder.buildModel();
            model.put("siteTitles", siteNames);
            model.put("repeatIntervalMins", repeatIntervalMins);
            model.put("feedItemsMax", activityService.getMaxFeedItems());
            // add Share info to model
            model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
            Map<String, Serializable> personPrefixProps = new HashMap<String, Serializable>(personProps.size());
            for (QName propQName : personProps.keySet()) {
                try {
                    String propPrefix = propQName.toPrefixString(namespaceService);
                    personPrefixProps.put(propPrefix, personProps.get(propQName));
                } catch (NamespaceException ne) {
                    // ignore properties that do not have a registered namespace
                    logger.warn("Ignoring property '" + propQName + "' as it's namespace is not registered");
                }
            }
            model.put("personProps", personPrefixProps);
            // send
            notifyUser(personNodeRef, subject, subjectParams, model, templateNodeRef);
            return new Pair<Integer, Long>(activityCount, modelBuilder.getMaxFeedId());
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) JSONException(org.json.JSONException) NamespaceException(org.alfresco.service.namespace.NamespaceException) JSONException(org.json.JSONException) ActivityFeedEntity(org.alfresco.repo.domain.activities.ActivityFeedEntity) NamespaceException(org.alfresco.service.namespace.NamespaceException) Pair(org.alfresco.util.Pair)

Example 3 with NamespaceException

use of org.alfresco.service.namespace.NamespaceException in project alfresco-repository by Alfresco.

the class ModelValidatorImpl method canDeleteModel.

private boolean canDeleteModel(Collection<NamespaceDefinition> namespaceDefs, Collection<TypeDefinition> typeDefs, Collection<AspectDefinition> aspectDefs, Tenant tenant) {
    boolean canDelete = true;
    String tenantDomain = "for tenant [" + (tenant == null ? TenantService.DEFAULT_DOMAIN : tenant.getTenantDomain()) + "]";
    List<WorkflowDefinition> workflowDefs = workflowService.getDefinitions();
    if (workflowDefs.size() > 0) {
        if (namespaceDefs.size() > 0) {
            // check workflow namespace usage
            for (WorkflowDefinition workflowDef : workflowDefs) {
                String workflowDefName = workflowDef.getName();
                String workflowNamespaceURI = null;
                try {
                    workflowNamespaceURI = QName.createQName(BPMEngineRegistry.getLocalId(workflowDefName), namespaceService).getNamespaceURI();
                } catch (NamespaceException ne) {
                    logger.warn("Skipped workflow when validating model delete - unknown namespace: " + ne);
                    continue;
                }
                for (NamespaceDefinition namespaceDef : namespaceDefs) {
                    if (workflowNamespaceURI.equals(namespaceDef.getUri())) {
                        logger.warn("Failed to validate model delete" + tenantDomain + " - found workflow process definition " + workflowDefName + " using model namespace '" + namespaceDef.getUri() + "'");
                        canDelete = false;
                    }
                }
            }
        }
    }
    // check for type usages
    outer: for (TypeDefinition type : typeDefs) {
        try {
            validateDeleteClass(tenant, type);
        } catch (ModelInUseException e) {
            canDelete = false;
            break outer;
        } catch (ModelNotInUseException e) {
        // ok, continue
        }
    }
    // check for aspect usages
    outer: for (AspectDefinition aspect : aspectDefs) {
        try {
            validateDeleteClass(tenant, aspect);
        } catch (ModelInUseException e) {
            canDelete = false;
            break outer;
        } catch (ModelNotInUseException e) {
        // ok, continue
        }
    }
    return canDelete;
}
Also used : WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) NamespaceException(org.alfresco.service.namespace.NamespaceException) NamespaceDefinition(org.alfresco.service.cmr.dictionary.NamespaceDefinition) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 4 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 5 with NamespaceException

use of org.alfresco.service.namespace.NamespaceException in project alfresco-repository by Alfresco.

the class AbstractRenderingEngine method setDefaultRenditionNodeType.

/**
 * Sets the default rendition-node type.
 *
 * @param type String
 */
public void setDefaultRenditionNodeType(String type) {
    QName qname;
    try {
        qname = QName.createQName(type);
    } catch (NamespaceException nx) {
        if (logger.isErrorEnabled()) {
            logger.error("Error when setting default rendition node type: ", nx);
        }
        throw nx;
    }
    if (logger.isInfoEnabled()) {
        logger.info("Using default rendition node type: " + qname);
    }
    this.defaultRenditionNodeType = qname;
}
Also used : 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