Search in sources :

Example 46 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project SearchServices by Alfresco.

the class ModelTracker method trackModelsImpl.

/**
 * Tracks models. Reflects changes and updates on disk copy
 *
 * @throws AuthenticationException
 * @throws IOException
 * @throws JSONException
 */
private void trackModelsImpl() throws AuthenticationException, IOException, JSONException {
    long start = System.nanoTime();
    List<AlfrescoModelDiff> modelDiffs = client.getModelsDiff(coreName, this.infoSrv.getAlfrescoModels());
    HashMap<String, M2Model> modelMap = new HashMap<String, M2Model>();
    for (AlfrescoModelDiff modelDiff : modelDiffs) {
        switch(modelDiff.getType()) {
            case CHANGED:
                AlfrescoModel changedModel = client.getModel(coreName, modelDiff.getModelName());
                for (M2Namespace namespace : changedModel.getModel().getNamespaces()) {
                    modelMap.put(namespace.getUri(), changedModel.getModel());
                }
                break;
            case NEW:
                AlfrescoModel newModel = client.getModel(coreName, modelDiff.getModelName());
                for (M2Namespace namespace : newModel.getModel().getNamespaces()) {
                    modelMap.put(namespace.getUri(), newModel.getModel());
                }
                break;
            case REMOVED:
                // We need to know the prefix for the uri to delete them
                break;
        }
    }
    HashSet<String> loadedModels = new HashSet<String>();
    for (M2Model model : modelMap.values()) {
        loadModel(modelMap, loadedModels, model);
    }
    if (loadedModels.size() > 0) {
        this.infoSrv.afterInitModels();
    }
    for (AlfrescoModelDiff modelDiff : modelDiffs) {
        switch(modelDiff.getType()) {
            case CHANGED:
                removeMatchingModels(alfrescoModelDir, modelDiff.getModelName());
                M2Model changedModel = this.infoSrv.getM2Model(modelDiff.getModelName());
                File changedFile = new File(alfrescoModelDir, getModelFileName(changedModel));
                FileOutputStream cos = new FileOutputStream(changedFile);
                changedModel.toXML(cos);
                cos.flush();
                cos.close();
                break;
            case NEW:
                M2Model newModel = this.infoSrv.getM2Model(modelDiff.getModelName());
                // add on file
                File newFile = new File(alfrescoModelDir, getModelFileName(newModel));
                FileOutputStream nos = new FileOutputStream(newFile);
                newModel.toXML(nos);
                nos.flush();
                nos.close();
                break;
            case REMOVED:
                // This will remove the model from the dictionary on completion
                try {
                    removeMatchingModels(alfrescoModelDir, modelDiff.getModelName());
                } finally {
                    AlfrescoSolrDataModel.getInstance().removeModel(modelDiff.getModelName());
                }
                break;
        }
    }
    long end = System.nanoTime();
    trackerStats.addModelTime(end - start);
    if (true == runPostModelLoadInit) {
        for (Object key : props.keySet()) {
            String stringKey = (String) key;
            if (stringKey.startsWith("alfresco.index.store")) {
                StoreRef store = new StoreRef(props.getProperty(stringKey));
                indexedStores.add(store);
            }
            if (stringKey.startsWith("alfresco.ignore.store")) {
                StoreRef store = new StoreRef(props.getProperty(stringKey));
                ignoredStores.add(store);
            }
            if (stringKey.startsWith("alfresco.index.tenant")) {
                indexedTenants.add(props.getProperty(stringKey));
            }
            if (stringKey.startsWith("alfresco.ignore.tenant")) {
                ignoredTenants.add(props.getProperty(stringKey));
            }
            if (stringKey.startsWith("alfresco.index.datatype")) {
                QName qname = expandQName(props.getProperty(stringKey));
                indexedDataTypes.add(qname);
            }
            if (stringKey.startsWith("alfresco.ignore.datatype")) {
                QName qname = expandQName(props.getProperty(stringKey));
                ignoredDataTypes.add(qname);
            }
            if (stringKey.startsWith("alfresco.index.type")) {
                QName qname = expandQName(props.getProperty(stringKey));
                indexedTypes.add(qname);
            }
            if (stringKey.startsWith("alfresco.ignore.type")) {
                QName qname = expandQName(props.getProperty(stringKey));
                ignoredTypes.add(qname);
            }
            if (stringKey.startsWith("alfresco.index.aspect")) {
                QName qname = expandQName(props.getProperty(stringKey));
                indexedAspects.add(qname);
            }
            if (stringKey.startsWith("alfresco.ignore.aspect")) {
                QName qname = expandQName(props.getProperty(stringKey));
                ignoredAspects.add(qname);
            }
            if (stringKey.startsWith("alfresco.index.field")) {
                String name = expandName(props.getProperty(stringKey));
                indexedFields.add(name);
            }
            if (stringKey.startsWith("alfresco.ignore.field")) {
                String name = expandName(props.getProperty(stringKey));
                ignoredFields.add(name);
            }
        }
        runPostModelLoadInit = false;
    }
}
Also used : M2Namespace(org.alfresco.repo.dictionary.M2Namespace) StoreRef(org.alfresco.service.cmr.repository.StoreRef) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoModelDiff(org.alfresco.solr.client.AlfrescoModelDiff) AlfrescoModel(org.alfresco.solr.client.AlfrescoModel) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashSet(java.util.HashSet)

Example 47 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class NodeBrowserPost method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> result = new HashMap<>(16);
    // gather inputs
    Map<String, String> returnParams = new HashMap<>(16);
    String store = req.getParameter("nodebrowser-store");
    String searcher = req.getParameter("nodebrowser-search");
    String query = req.getParameter("nodebrowser-query");
    String maxResults = req.getParameter("nodebrowser-query-maxresults");
    String skipCount = req.getParameter("nodebrowser-query-skipcount");
    String error = null;
    StoreRef storeRef = new StoreRef(store);
    // always a list of assoc refs from some result
    List<ChildAssociationRef> assocRefs = Collections.<ChildAssociationRef>emptyList();
    NodeRef currentNode = null;
    // what action should be processed?
    long timeStart = System.currentTimeMillis();
    String actionValue = req.getParameter("nodebrowser-action-value");
    String action = req.getParameter("nodebrowser-action");
    final String execute = req.getParameter("nodebrowser-execute");
    final String executeValue = req.getParameter("nodebrowser-execute-value");
    String message = null;
    try {
        // this is done before the view action to ensure node state is correct
        if (execute != null) {
            switch(execute) {
                case "delete":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                // delete the node using the standard NodeService
                                nodeService.deleteNode(new NodeRef(executeValue));
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.delete";
                        break;
                    }
                case "fdelete":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                // delete the node - but ensure that it is not archived
                                NodeRef ref = new NodeRef(executeValue);
                                nodeService.addAspect(ref, ContentModel.ASPECT_TEMPORARY, null);
                                nodeService.deleteNode(ref);
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.delete";
                        break;
                    }
                case "restore":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                nodeService.restoreNode(new NodeRef(executeValue), null, null, null);
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.restore";
                        break;
                    }
                case "take-ownership":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                ownableService.takeOwnership(new NodeRef(executeValue));
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.take-ownership";
                        break;
                    }
                case "delete-permissions":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                NodeRef ref = new NodeRef(executeValue);
                                permissionService.deletePermissions(ref);
                                permissionService.setInheritParentPermissions(ref, true);
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.delete-permissions";
                        break;
                    }
                case "delete-property":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                // argument value contains "NodeRef|QName" packed string
                                String[] parts = executeValue.split("\\|");
                                nodeService.removeProperty(new NodeRef(parts[0]), QName.createQName(parts[1]));
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.delete-property";
                        break;
                    }
                case "unlock":
                    {
                        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                            @Override
                            public Void execute() throws Throwable {
                                NodeRef ref = new NodeRef(executeValue);
                                if (cociService.isCheckedOut(ref)) {
                                    NodeRef wcRef = cociService.getWorkingCopy(ref);
                                    if (wcRef != null) {
                                        cociService.cancelCheckout(wcRef);
                                    }
                                } else {
                                    lockService.unlock(ref);
                                }
                                return null;
                            }
                        }, false, true);
                        message = "nodebrowser.message.unlock";
                        break;
                    }
            }
        }
        // the 'actionValue' param provides context as may other parameters such as 'query'
        switch(action) {
            // on Execute btn press and query present, perform search
            case "search":
                {
                    if (query != null && query.trim().length() != 0) {
                        switch(searcher) {
                            case "noderef":
                                {
                                    // ensure node exists - or throw error
                                    NodeRef nodeRef = new NodeRef(query);
                                    boolean exists = getNodeService().exists(nodeRef);
                                    if (!exists) {
                                        throw new AlfrescoRuntimeException("Node " + nodeRef + " does not exist.");
                                    }
                                    currentNode = nodeRef;
                                    // this is not really a search for results, it is a direct node reference
                                    // so gather the child assocs as usual and update the action value for the UI location
                                    assocRefs = getNodeService().getChildAssocs(currentNode);
                                    actionValue = query;
                                    action = "parent";
                                    break;
                                }
                            case "selectnodes":
                                {
                                    List<NodeRef> nodes = getSearchService().selectNodes(getNodeService().getRootNode(storeRef), query, null, getNamespaceService(), false);
                                    assocRefs = new ArrayList<>(nodes.size());
                                    for (NodeRef node : nodes) {
                                        assocRefs.add(getNodeService().getPrimaryParent(node));
                                    }
                                    break;
                                }
                            default:
                                {
                                    // perform search
                                    SearchParameters params = new SearchParameters();
                                    params.setQuery(query);
                                    params.addStore(storeRef);
                                    params.setLanguage(searcher);
                                    if (maxResults != null && maxResults.length() != 0) {
                                        params.setMaxItems(Integer.parseInt(maxResults));
                                        params.setLimit(Integer.parseInt(maxResults));
                                    }
                                    if (skipCount != null && skipCount.length() != 0) {
                                        params.setSkipCount(Integer.parseInt(skipCount));
                                    }
                                    ResultSet rs = getSearchService().query(params);
                                    assocRefs = rs.getChildAssocRefs();
                                    break;
                                }
                        }
                    }
                    break;
                }
            case "root":
                {
                    // iterate the properties and children of a store root node
                    currentNode = getNodeService().getRootNode(storeRef);
                    assocRefs = getNodeService().getChildAssocs(currentNode);
                    break;
                }
            case "parent":
            case "children":
                {
                    currentNode = new NodeRef(actionValue);
                    assocRefs = getNodeService().getChildAssocs(currentNode);
                    break;
                }
        }
        // get the required information from the assocRefs list and wrap objects
        List<ChildAssocRefWrapper> wrappers = new ArrayList<>(assocRefs.size());
        for (ChildAssociationRef ref : assocRefs) {
            wrappers.add(new ChildAssocRefWrapper(ref));
        }
        result.put("children", wrappers);
    } catch (Throwable e) {
        // empty child list on error - current node will still be null
        result.put("children", new ArrayList<>(0));
        error = e.getMessage();
    }
    // current node info if any
    if (currentNode != null) {
        // node info
        Map<String, Object> info = new HashMap<>(8);
        info.put("nodeRef", currentNode.toString());
        info.put("path", getNodeService().getPath(currentNode).toPrefixString(getNamespaceService()));
        info.put("type", getNodeService().getType(currentNode).toPrefixString(getNamespaceService()));
        ChildAssociationRef parent = getNodeService().getPrimaryParent(currentNode);
        info.put("parent", parent.getParentRef() != null ? parent.getParentRef().toString() : "");
        result.put("info", info);
        // node properties
        result.put("properties", getProperties(currentNode));
        // parents
        List<ChildAssociationRef> parents = getNodeService().getParentAssocs(currentNode);
        List<ChildAssociation> assocs = new ArrayList<ChildAssociation>(parents.size());
        for (ChildAssociationRef ref : parents) {
            assocs.add(new ChildAssociation(ref));
        }
        result.put("parents", assocs);
        // aspects
        List<Aspect> aspects = getAspects(currentNode);
        result.put("aspects", aspects);
        // target assocs
        List<PeerAssociation> targetAssocs = getAssocs(currentNode);
        result.put("assocs", targetAssocs);
        // source assocs
        List<PeerAssociation> sourceAssocs = getSourceAssocs(currentNode);
        result.put("sourceAssocs", sourceAssocs);
        // permissions
        Map<String, Object> permissionInfo = new HashMap<String, Object>();
        permissionInfo.put("entries", getPermissions(currentNode));
        permissionInfo.put("owner", getOwnableService().getOwner(currentNode));
        permissionInfo.put("inherit", getInheritPermissions(currentNode));
        result.put("permissions", permissionInfo);
    }
    // store result in session for the resulting GET request webscript
    final String resultId = GUID.generate();
    HttpServletRequest request = ((WebScriptServletRequest) req).getHttpServletRequest();
    HttpSession session = request.getSession();
    session.putValue(resultId, result);
    // return params
    returnParams.put("resultId", resultId);
    returnParams.put("action", action);
    returnParams.put("actionValue", actionValue);
    returnParams.put("query", query);
    returnParams.put("store", store);
    returnParams.put("searcher", searcher);
    returnParams.put("maxResults", maxResults);
    returnParams.put("skipCount", skipCount);
    returnParams.put("in", Long.toString(System.currentTimeMillis() - timeStart));
    returnParams.put("e", error);
    returnParams.put("m", message);
    // redirect as all admin console pages do (follow standard pattern)
    // The logic to generate the navigation section and server meta-data is all tied into alfresco-common.lib.js
    // which is great for writing JS based JMX surfaced pages, but not so great for Java backed WebScripts.
    status.setCode(301);
    status.setRedirect(true);
    status.setLocation(buildUrl(req, returnParams, execute != null && execute.length() != 0 ? execute : action));
    return null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) WebScriptServletRequest(org.springframework.extensions.webscripts.servlet.WebScriptServletRequest) StoreRef(org.alfresco.service.cmr.repository.StoreRef) HttpSession(javax.servlet.http.HttpSession) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 48 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class AbstractArchivedNodeWebScript method parseRequestForStoreRef.

protected StoreRef parseRequestForStoreRef(WebScriptRequest req) {
    // get the parameters that represent the StoreRef, we know they are present
    // otherwise this webscript would not have matched
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String storeType = templateVars.get("store_type");
    String storeId = templateVars.get("store_id");
    // create the StoreRef and ensure it is valid
    StoreRef storeRef = new StoreRef(storeType, storeId);
    return storeRef;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef)

Example 49 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class ArchivedNodesGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // We want to get all nodes in the archive which were originally
    // contained in the following StoreRef.
    StoreRef storeRef = parseRequestForStoreRef(req);
    // Create paging
    ScriptPagingDetails paging = new ScriptPagingDetails(getIntParameter(req, MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE), getIntParameter(req, SKIP_COUNT, 0));
    PagingResults<NodeRef> result = getArchivedNodesFrom(storeRef, paging, req.getParameter(NAME_FILTER));
    List<NodeRef> nodeRefs = result.getPage();
    List<ArchivedNodeState> deletedNodes = new ArrayList<ArchivedNodeState>(nodeRefs.size());
    for (NodeRef archivedNode : nodeRefs) {
        ArchivedNodeState state = ArchivedNodeState.create(archivedNode, serviceRegistry);
        deletedNodes.add(state);
    }
    // Now do the paging
    // ALF-19111. Note: Archived nodes CQ, supports Paging,
    // so no need to use the ModelUtil.page method to build the page again.
    model.put(DELETED_NODES, deletedNodes);
    // Because we haven't used ModelUtil.page method, we need to set the total items manually.
    paging.setTotalItems(deletedNodes.size());
    model.put("paging", ModelUtil.buildPaging(paging));
    return model;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Example 50 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class AbstractRatingWebScript method parseRequestForNodeRef.

protected NodeRef parseRequestForNodeRef(WebScriptRequest req) {
    // get the parameters that represent the NodeRef, we know they are present
    // otherwise this webscript would not have matched
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String storeType = templateVars.get("store_type");
    String storeId = templateVars.get("store_id");
    String nodeId = templateVars.get("id");
    // create the NodeRef and ensure it is valid
    StoreRef storeRef = new StoreRef(storeType, storeId);
    NodeRef nodeRef = new NodeRef(storeRef, nodeId);
    if (!this.nodeService.exists(nodeRef)) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString());
    }
    return nodeRef;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Aggregations

StoreRef (org.alfresco.service.cmr.repository.StoreRef)67 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)18 QName (org.alfresco.service.namespace.QName)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)13 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)13 PropertyValue (org.alfresco.solr.client.PropertyValue)11 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)10 ArrayList (java.util.ArrayList)9 ContentPropertyValue (org.alfresco.solr.client.ContentPropertyValue)9 MLTextPropertyValue (org.alfresco.solr.client.MLTextPropertyValue)9 IOException (java.io.IOException)7 Date (java.util.Date)6 MultiPropertyValue (org.alfresco.solr.client.MultiPropertyValue)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 PermissionService (org.alfresco.service.cmr.security.PermissionService)5 SolrCore (org.apache.solr.core.SolrCore)5 StringTokenizer (java.util.StringTokenizer)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4