Search in sources :

Example 16 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project records-management by Alfresco.

the class DeclarativeReportGenerator method getReportDisplayLabel.

/**
 * Helper method to get the report types display label
 *
 * @return  {@link String}  report type display label
 */
private String getReportDisplayLabel() {
    String result = I18NUtil.getMessage(MSG_REPORT);
    TypeDefinition typeDef = dictionaryService.getType(reportType);
    if (typeDef != null) {
        result = typeDef.getTitle(new StaticMessageLookup());
    }
    return result;
}
Also used : StaticMessageLookup(org.alfresco.repo.i18n.StaticMessageLookup) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 17 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project records-management by Alfresco.

the class RecordsManagementAuditServiceImpl method getAuditTrailImpl.

/**
 * Get the audit trail, optionally dumping the results the the given writer dumping to a list.
 *
 * @param params                the search parameters
 * @param results               the list to which individual results will be dumped
 * @param writer                Writer to write the audit trail
 * @param reportFormat          Format to write the audit trail in, ignored if writer is <code>null</code>
 */
protected void getAuditTrailImpl(final RecordsManagementAuditQueryParameters params, final List<RecordsManagementAuditEntry> results, final Writer writer, final ReportFormat reportFormat) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieving audit trail in '" + reportFormat + "' format using parameters: " + params);
    }
    // define the callback
    AuditQueryCallback callback = new AuditQueryCallback() {

        private boolean firstEntry = true;

        @Override
        public boolean valuesRequired() {
            return true;
        }

        /**
         * Just log the error, but continue
         */
        @Override
        public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
            logger.warn(errorMsg, error);
            return true;
        }

        @Override
        @SuppressWarnings("unchecked")
        public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) {
            // Check for context shutdown
            if (shutdown) {
                return false;
            }
            Date timestamp = new Date(time);
            String eventName = null;
            String fullName = null;
            String userRoles = null;
            NodeRef nodeRef = null;
            String nodeName = null;
            String nodeType = null;
            String nodeIdentifier = null;
            String namePath = null;
            Map<QName, Serializable> beforeProperties = null;
            Map<QName, Serializable> afterProperties = null;
            if (values.containsKey(RM_AUDIT_DATA_EVENT_NAME)) {
                // This data is /RM/event/...
                eventName = (String) values.get(RM_AUDIT_DATA_EVENT_NAME);
                fullName = (String) values.get(RM_AUDIT_DATA_PERSON_FULLNAME);
                userRoles = (String) values.get(RM_AUDIT_DATA_PERSON_ROLES);
                nodeRef = (NodeRef) values.get(RM_AUDIT_DATA_NODE_NODEREF);
                nodeName = (String) values.get(RM_AUDIT_DATA_NODE_NAME);
                QName nodeTypeQname = (QName) values.get(RM_AUDIT_DATA_NODE_TYPE);
                nodeIdentifier = (String) values.get(RM_AUDIT_DATA_NODE_IDENTIFIER);
                namePath = (String) values.get(RM_AUDIT_DATA_NODE_NAMEPATH);
                beforeProperties = (Map<QName, Serializable>) values.get(RM_AUDIT_DATA_NODE_CHANGES_BEFORE);
                afterProperties = (Map<QName, Serializable>) values.get(RM_AUDIT_DATA_NODE_CHANGES_AFTER);
                // Convert some of the values to recognizable forms
                nodeType = null;
                if (nodeTypeQname != null) {
                    TypeDefinition typeDef = dictionaryService.getType(nodeTypeQname);
                    nodeType = (typeDef != null) ? typeDef.getTitle(dictionaryService) : null;
                }
            } else if (values.containsKey(DOD5015_AUDIT_DATA_EVENT_NAME)) {
                // This data is /RM/event/...
                eventName = (String) values.get(DOD5015_AUDIT_DATA_EVENT_NAME);
                fullName = (String) values.get(DOD5015_AUDIT_DATA_PERSON_FULLNAME);
                userRoles = (String) values.get(DOD5015_AUDIT_DATA_PERSON_ROLES);
                nodeRef = (NodeRef) values.get(DOD5015_AUDIT_DATA_NODE_NODEREF);
                nodeName = (String) values.get(DOD5015_AUDIT_DATA_NODE_NAME);
                QName nodeTypeQname = (QName) values.get(DOD5015_AUDIT_DATA_NODE_TYPE);
                nodeIdentifier = (String) values.get(DOD5015_AUDIT_DATA_NODE_IDENTIFIER);
                namePath = (String) values.get(DOD5015_AUDIT_DATA_NODE_NAMEPATH);
                beforeProperties = (Map<QName, Serializable>) values.get(DOD5015_AUDIT_DATA_NODE_CHANGES_BEFORE);
                afterProperties = (Map<QName, Serializable>) values.get(DOD5015_AUDIT_DATA_NODE_CHANGES_AFTER);
                // Convert some of the values to recognizable forms
                nodeType = null;
                if (nodeTypeQname != null) {
                    TypeDefinition typeDef = dictionaryService.getType(nodeTypeQname);
                    nodeType = (typeDef != null) ? typeDef.getTitle(dictionaryService) : null;
                }
            } else if (values.containsKey(RM_AUDIT_DATA_LOGIN_USERNAME)) {
                user = (String) values.get(RM_AUDIT_DATA_LOGIN_USERNAME);
                if (values.containsKey(RM_AUDIT_DATA_LOGIN_ERROR)) {
                    eventName = RM_AUDIT_EVENT_LOGIN_FAILURE;
                    // The user didn't log in
                    fullName = user;
                } else {
                    eventName = RM_AUDIT_EVENT_LOGIN_SUCCESS;
                    fullName = (String) values.get(RM_AUDIT_DATA_LOGIN_FULLNAME);
                }
            } else if (values.containsKey(DOD5015_AUDIT_DATA_LOGIN_USERNAME)) {
                user = (String) values.get(DOD5015_AUDIT_DATA_LOGIN_USERNAME);
                if (values.containsKey(DOD5015_AUDIT_DATA_LOGIN_ERROR)) {
                    eventName = RM_AUDIT_EVENT_LOGIN_FAILURE;
                    // The user didn't log in
                    fullName = user;
                } else {
                    eventName = RM_AUDIT_EVENT_LOGIN_SUCCESS;
                    fullName = (String) values.get(DOD5015_AUDIT_DATA_LOGIN_FULLNAME);
                }
            } else {
                // This is not recognisable data
                logger.warn("Unable to process audit entry for RM.  Unexpected data: \n" + "   Entry: " + entryId + "\n" + "   Data:  " + values);
                // Skip it
                return true;
            }
            if (nodeRef != null && nodeService.exists(nodeRef) && !AccessStatus.ALLOWED.equals(capabilityService.getCapabilityAccessState(nodeRef, ACCESS_AUDIT_CAPABILITY))) {
                return true;
            }
            // TODO: Refactor this to use the builder pattern
            RecordsManagementAuditEntry entry = new RecordsManagementAuditEntry(timestamp, user, fullName, // A concatenated string of roles
            userRoles, nodeRef, nodeName, nodeType, eventName, nodeIdentifier, namePath, beforeProperties, afterProperties);
            // write out the entry to the file in requested format
            writeEntryToFile(entry);
            if (results != null) {
                results.add(entry);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("   " + entry);
            }
            // Keep going
            return true;
        }

        private void writeEntryToFile(RecordsManagementAuditEntry entry) {
            if (writer == null) {
                return;
            }
            try {
                if (!firstEntry) {
                    if (reportFormat == ReportFormat.HTML) {
                        writer.write("\n");
                    } else {
                        writer.write(",");
                    }
                } else {
                    firstEntry = false;
                }
                // write the entry to the file
                if (reportFormat == ReportFormat.JSON) {
                    writer.write("\n\t\t");
                }
                writeAuditTrailEntry(writer, entry, reportFormat);
            } catch (IOException ioe) {
                throw new AlfrescoRuntimeException(MSG_TRAIL_FILE_FAIL, ioe);
            }
        }
    };
    String user = params.getUser();
    Long fromTime = getFromDateTime(params.getDateFrom());
    Long toTime = getToDateTime(params.getDateTo());
    NodeRef nodeRef = params.getNodeRef();
    int maxEntries = params.getMaxEntries();
    // Reverse order if the results are limited
    boolean forward = maxEntries > 0 ? false : true;
    // start the audit trail report
    writeAuditTrailHeader(writer, params, reportFormat);
    if (logger.isDebugEnabled()) {
        logger.debug("RM Audit: Issuing query: " + params);
    }
    // Build audit query parameters
    AuditQueryParameters dod5015AuditQueryParams = new AuditQueryParameters();
    dod5015AuditQueryParams.setForward(forward);
    dod5015AuditQueryParams.setApplicationName(DOD5015_AUDIT_APPLICATION_NAME);
    dod5015AuditQueryParams.setUser(user);
    dod5015AuditQueryParams.setFromTime(fromTime);
    dod5015AuditQueryParams.setToTime(toTime);
    if (nodeRef != null) {
        dod5015AuditQueryParams.addSearchKey(DOD5015_AUDIT_DATA_NODE_NODEREF, nodeRef);
    }
    // 
    AuditQueryParameters auditQueryParams = new AuditQueryParameters();
    auditQueryParams.setForward(forward);
    auditQueryParams.setApplicationName(RM_AUDIT_APPLICATION_NAME);
    auditQueryParams.setUser(user);
    auditQueryParams.setFromTime(fromTime);
    auditQueryParams.setToTime(toTime);
    if (nodeRef != null) {
        auditQueryParams.addSearchKey(RM_AUDIT_DATA_NODE_NODEREF, nodeRef);
    } else if (params.getEvent() != null) {
        auditQueryParams.addSearchKey(RM_AUDIT_DATA_EVENT_NAME, params.getEvent());
    }
    // Get audit entries
    SiteInfo siteInfo = siteService.getSite(DEFAULT_SITE_NAME);
    if (siteInfo != null) {
        QName siteType = nodeService.getType(siteInfo.getNodeRef());
        if (siteType.equals(TYPE_DOD_5015_SITE)) {
            auditService.auditQuery(callback, dod5015AuditQueryParams, maxEntries);
        }
    }
    // We always need to make the standard query - regardless of the type of RM site (to get events like RM site created).
    auditService.auditQuery(callback, auditQueryParams, maxEntries);
    // finish off the audit trail report
    writeAuditTrailFooter(writer, reportFormat);
    // audit that the audit has been view'ed
    if (nodeRef == null) {
        // grab the default file plan, but don't fail if it can't be found!
        nodeRef = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
    }
    auditEvent(nodeRef, AUDIT_EVENT_VIEW, null, null, true);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) AuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters) IOException(java.io.IOException) Date(java.util.Date) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AuditQueryCallback(org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) PropertyMap(org.alfresco.util.PropertyMap)

Example 18 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class BrowseBean method deleteFile.

/**
 * Event handler used when a file is being deleted, checks that the node
 * does not have an associated working copy.
 *
 * @param event The event
 */
public void deleteFile(ActionEvent event) {
    setupContentAction(event);
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String ref = params.get("ref");
    if (ref != null && ref.length() > 0) {
        NodeRef nodeRef = new NodeRef(ref);
        NodeRef workingCopyNodeRef = getCheckOutCheckInService().getWorkingCopy(nodeRef);
        if (workingCopyNodeRef != null) {
            // if node has a working copy setup error message and return
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_CANNOT_DELETE_NODE_HAS_WORKING_COPY), new Object[] { getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME) }));
            return;
        }
        // if there isn't a working copy go to normal delete dialog
        boolean hasMultipleParents = false;
        boolean showDeleteAssocDialog = false;
        // get type of node being deleted
        Node node = this.getDocument();
        QName type = node.getType();
        TypeDefinition typeDef = this.dictionaryService.getType(type);
        // determine if the node being delete has multiple parents
        if (!type.equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER) && !node.hasAspect(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION) && !node.hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) && !type.equals(ContentModel.TYPE_LINK) && !this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_LINK)) {
            List<ChildAssociationRef> parents = this.nodeService.getParentAssocs(node.getNodeRef(), ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            if (parents != null && parents.size() > 1) {
                hasMultipleParents = true;
            }
        }
        // determine which delete dialog to display
        if (this.navigator.getSearchContext() == null && hasMultipleParents) {
            // if we are not in a search and the node has multiple parents
            // see if the current node has the primary parent association
            NodeRef parentSpace = this.navigator.getCurrentNode().getNodeRef();
            ChildAssociationRef assoc = this.nodeService.getPrimaryParent(node.getNodeRef());
            // show delete assoc dialog if the current space is not the primary parent for the node
            showDeleteAssocDialog = !parentSpace.equals(assoc.getParentRef());
        }
        // show the appropriate dialog
        FacesContext fc = FacesContext.getCurrentInstance();
        if (showDeleteAssocDialog) {
            fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:deleteFileAssoc");
        } else {
            final Map<String, String> dialogParams = new HashMap<String, String>(1);
            dialogParams.put("hasMultipleParents", Boolean.toString(hasMultipleParents));
            Application.getDialogManager().setupParameters(dialogParams);
            fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:deleteFile");
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) HashMap(java.util.HashMap) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 19 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class BrowseBean method getParentNodes.

/**
 * Page accessed bean method to get the parent container nodes currently being browsed
 *
 * @return List of parent container Node objects for the current browse location
 */
public List<Node> getParentNodes(NodeRef currNodeRef) {
    if (this.parentContainerNodes == null) {
        long startTime = 0;
        if (logger.isDebugEnabled())
            startTime = System.currentTimeMillis();
        UserTransaction tx = null;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            NodeRef parentRef = getNodeService().getPrimaryParent(currNodeRef).getParentRef();
            List<FileInfo> children = this.getFileFolderService().list(parentRef);
            this.parentContainerNodes = new ArrayList<Node>(children.size());
            for (FileInfo fileInfo : children) {
                // create our Node representation from the NodeRef
                NodeRef nodeRef = fileInfo.getNodeRef();
                // find it's type so we can see if it's a node we are interested in
                QName type = this.getNodeService().getType(nodeRef);
                // make sure the type is defined in the data dictionary
                TypeDefinition typeDef = this.getDictionaryService().getType(type);
                if (typeDef != null) {
                    MapNode node = null;
                    // look for Space folder node
                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        // create our Node representation
                        node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.parentContainerNodes.add(node);
                    } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                        // create our Folder Link Node representation
                        node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.parentContainerNodes.add(node);
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                }
            }
            // commit the transaction
            tx.commit();
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
            this.parentContainerNodes = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (Throwable err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
            this.parentContainerNodes = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
        if (logger.isDebugEnabled()) {
            long endTime = System.currentTimeMillis();
            logger.debug("Time to query and build map parent nodes: " + (endTime - startTime) + "ms");
        }
    }
    List<Node> result = this.parentContainerNodes;
    return result;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 20 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.

the class BrowseBean method searchBrowseNodes.

/**
 * Search for a list of nodes using the specific search context
 *
 * @param searchContext    To use to perform the search
 */
private void searchBrowseNodes(SearchContext searchContext) {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    // get the searcher object to build the query
    String query = searchContext.buildQuery(getMinimumSearchLength());
    if (query == null) {
        // failed to build a valid query, the user probably did not enter the
        // minimum text required to construct a valid search
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_SEARCH_MINIMUM), new Object[] { getMinimumSearchLength() }));
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        return;
    }
    // perform the search against the repo
    UserTransaction tx = null;
    ResultSet results = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        // build up the search parameters
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(query);
        sp.addStore(Repository.getStoreRef());
        // limit search results size as configured
        int searchLimit = Application.getClientConfig(FacesContext.getCurrentInstance()).getSearchMaxResults();
        if (searchLimit > 0) {
            sp.setLimitBy(LimitBy.FINAL_SIZE);
            sp.setLimit(searchLimit);
        }
        sp.setBulkFetchEnabled(Application.getClientConfig(FacesContext.getCurrentInstance()).isBulkFetchEnabled());
        results = this.getSearchService().query(sp);
        if (logger.isDebugEnabled())
            logger.debug("Search results returned: " + results.length());
        // create a list of items from the results
        this.containerNodes = new ArrayList<Node>(results.length());
        this.contentNodes = new ArrayList<Node>(results.length());
        if (results.length() != 0) {
            // in case of dynamic config, only lookup once
            Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
            for (ResultSetRow row : results) {
                NodeRef nodeRef = row.getNodeRef();
                if (this.getNodeService().exists(nodeRef)) {
                    // find it's type so we can see if it's a node we are interested in
                    QName type = this.getNodeService().getType(nodeRef);
                    // make sure the type is defined in the data dictionary
                    TypeDefinition typeDef = this.getDictionaryService().getType(type);
                    if (typeDef != null) {
                        MapNode node = null;
                        // look for Space or File nodes
                        if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                            // create our Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            node.addPropertyResolver("path", this.resolverPath);
                            node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                            node.addPropertyResolver("icon", this.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                            this.containerNodes.add(node);
                        } else if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                            // create our Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            setupCommonBindingProperties(node);
                            node.addPropertyResolver("path", this.resolverPath);
                            node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                            this.contentNodes.add(node);
                        } else // look for File Link object node
                        if (ApplicationModel.TYPE_FILELINK.equals(type)) {
                            // create our File Link Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            // only display the user has the permissions to navigate to the target of the link
                            NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                            if (new Node(destRef).hasPermission(PermissionService.READ) == true) {
                                node.addPropertyResolver("url", this.resolverLinkUrl);
                                node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
                                node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
                                node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
                                node.addPropertyResolver("fileType16", this.resolverFileType16);
                                node.addPropertyResolver("fileType32", this.resolverFileType32);
                                node.addPropertyResolver("lang", this.resolverLang);
                                node.addPropertyResolver("path", this.resolverPath);
                                node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                                this.contentNodes.add(node);
                            }
                        } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                            // create our Folder Link Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            // only display the user has the permissions to navigate to the target of the link
                            NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                            if (new Node(destRef).hasPermission(PermissionService.READ) == true) {
                                node.addPropertyResolver("icon", this.resolverSpaceIcon);
                                node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                                node.addPropertyResolver("path", this.resolverPath);
                                node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                                this.containerNodes.add(node);
                            }
                        }
                        // inform any listeners that a Node wrapper has been created
                        if (node != null) {
                            for (NodeEventListener listener : nodeEventListeners) {
                                listener.created(node, type);
                            }
                        }
                    } else {
                        if (logger.isWarnEnabled())
                            logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Missing object returned from search indexes: id = " + nodeRef + " search query: " + query);
                }
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (SearcherException serr) {
        logger.info("Search failed for: " + query, serr);
        Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_QUERY));
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_SEARCH), new Object[] { err.getMessage() }), err);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearcherException(org.alfresco.repo.search.SearcherException) ResultSet(org.alfresco.service.cmr.search.ResultSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Aggregations

TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)43 QName (org.alfresco.service.namespace.QName)30 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 FacesContext (javax.faces.context.FacesContext)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 StartFormData (org.activiti.engine.form.StartFormData)8 IOException (java.io.IOException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Node (org.alfresco.web.bean.repository.Node)7 UserTransaction (javax.transaction.UserTransaction)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)6 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Date (java.util.Date)5 SelectItem (javax.faces.model.SelectItem)5 MapNode (org.alfresco.web.bean.repository.MapNode)5 Serializable (java.io.Serializable)4 List (java.util.List)4