Search in sources :

Example 26 with DictionaryService

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

the class BaseInviteUsersWizard method getEmailTemplates.

/**
 * @return Returns the list of email templates for user notification
 */
public List<SelectItem> getEmailTemplates() {
    List<SelectItem> wrappers = null;
    try {
        FacesContext fc = FacesContext.getCurrentInstance();
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
        List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, getEmailTemplateXPath(), null, resolver, false);
        wrappers = new ArrayList<SelectItem>(results.size() + 1);
        if (results.size() != 0) {
            DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
            for (NodeRef ref : results) {
                if (this.getNodeService().exists(ref) == true) {
                    Node childNode = new Node(ref);
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
                        wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
                    }
                }
            }
            // make sure the list is sorted by the label
            QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
            sorter.sort();
        }
    } catch (AccessDeniedException accessErr) {
    // ignore the result if we cannot access the root
    }
    // add an entry (at the start) to instruct the user to select an item
    if (wrappers == null) {
        wrappers = new ArrayList<SelectItem>(1);
    }
    wrappers.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
    return wrappers;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NamespaceService(org.alfresco.service.namespace.NamespaceService) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node)

Example 27 with DictionaryService

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

the class AdvancedSearchDialog method getFolderTypes.

/**
 * @return Returns a list of folder object types to allow the user to select from
 */
public List<SelectItem> getFolderTypes() {
    if ((properties.getFolderTypes() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
        // add the well known cm:folder object type by default
        properties.setFolderTypes(new ArrayList<SelectItem>(5));
        properties.getFolderTypes().add(new SelectItem(ContentModel.TYPE_FOLDER.toString(), dictionaryService.getType(ContentModel.TYPE_FOLDER).getTitle(dictionaryService)));
        // add any configured folder sub-types to the list
        List<String> types = getSearchConfig().getFolderTypes();
        if (types != null) {
            for (String type : types) {
                QName idQName = Repository.resolveToQName(type);
                if (idQName != null) {
                    TypeDefinition typeDef = dictionaryService.getType(idQName);
                    if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER)) {
                        // try and get label from the dictionary
                        String label = typeDef.getTitle(dictionaryService);
                        // else just use the localname
                        if (label == null) {
                            label = idQName.getLocalName();
                        }
                        properties.getFolderTypes().add(new SelectItem(idQName.toString(), label));
                    }
                }
            }
        }
    }
    return properties.getFolderTypes();
}
Also used : FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 28 with DictionaryService

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

the class UserShortcutsBean method click.

/**
 * Action handler bound to the user shortcuts Shelf component called when a node is clicked
 */
public void click(ActionEvent event) {
    // work out which node was clicked from the event data
    UIShortcutsShelfItem.ShortcutEvent shortcutEvent = (UIShortcutsShelfItem.ShortcutEvent) event;
    Node selectedNode = getShortcuts().get(shortcutEvent.Index);
    try {
        if (getPermissionService().hasPermission(selectedNode.getNodeRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
            if (getNodeService().exists(selectedNode.getNodeRef()) == false) {
                throw new InvalidNodeRefException(selectedNode.getNodeRef());
            }
            DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
            if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_FOLDER)) {
                // then navigate to the appropriate node in UI
                // use browse bean functionality for this as it will update the breadcrumb for us
                this.browseBean.updateUILocation(selectedNode.getNodeRef());
            } else if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_CONTENT)) {
                // view details for document
                this.browseBean.setupContentAction(selectedNode.getId(), true);
                FacesContext fc = FacesContext.getCurrentInstance();
                fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:showDocDetails");
            }
        } else {
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "error_shortcut_permissions"));
        }
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { selectedNode.getId() }));
        // remove item from the shortcut list
        UserTransaction tx = null;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            tx = Repository.getUserTransaction(context);
            tx.begin();
            List<String> shortcuts = getShortcutList(context);
            if (shortcuts.size() > shortcutEvent.Index) {
                // remove the shortcut from the saved list and persist back
                shortcuts.remove(shortcutEvent.Index);
                PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
                // commit the transaction
                tx.commit();
                // remove shortcut Node from the in-memory list
                Node node = getShortcuts().remove(shortcutEvent.Index);
                if (logger.isDebugEnabled())
                    logger.debug("Removed deleted node: " + node.getName() + " from the user shortcuts list.");
            }
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) Serializable(java.io.Serializable) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ArrayList(java.util.ArrayList) List(java.util.List) UIShortcutsShelfItem(org.alfresco.web.ui.repo.component.shelf.UIShortcutsShelfItem) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException)

Example 29 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project alfresco-remote-api by Alfresco.

the class WorkflowModelBuilderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    namespaceService = new NamespaceServiceMemoryImpl();
    namespaceService.registerNamespace("test", URI);
    namespaceService.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI);
    namespaceService.registerNamespace(NamespaceService.BPM_MODEL_PREFIX, NamespaceService.BPM_MODEL_1_0_URI);
    personService = mock(PersonService.class);
    when(personService.getPerson(userName)).thenReturn(person);
    when(personService.personExists(userName)).thenReturn(true);
    nodeService = mock(NodeService.class);
    Map<QName, Serializable> personProps = new HashMap<QName, Serializable>();
    personProps.put(ContentModel.PROP_USERNAME, userName);
    personProps.put(ContentModel.PROP_FIRSTNAME, firstName);
    personProps.put(ContentModel.PROP_LASTNAME, lastName);
    when(nodeService.getProperties(person)).thenReturn(personProps);
    when(nodeService.getProperty(person, ContentModel.PROP_USERNAME)).thenReturn(userName);
    when(nodeService.getProperty(person, ContentModel.PROP_FIRSTNAME)).thenReturn(firstName);
    when(nodeService.getProperty(person, ContentModel.PROP_LASTNAME)).thenReturn(lastName);
    workflowService = mock(WorkflowService.class);
    dictionaryService = mock(DictionaryService.class);
    authenticationService = mock(AuthenticationService.class);
    builder = new WorkflowModelBuilder(namespaceService, nodeService, authenticationService, personService, workflowService, dictionaryService);
}
Also used : Serializable(java.io.Serializable) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) HashMap(java.util.HashMap) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) QName(org.alfresco.service.namespace.QName) NamespaceServiceMemoryImpl(org.alfresco.service.namespace.NamespaceServiceMemoryImpl) PersonService(org.alfresco.service.cmr.security.PersonService) NodeService(org.alfresco.service.cmr.repository.NodeService) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Aggregations

DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)29 FacesContext (javax.faces.context.FacesContext)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 QName (org.alfresco.service.namespace.QName)11 NodeService (org.alfresco.service.cmr.repository.NodeService)8 Node (org.alfresco.web.bean.repository.Node)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)7 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)6 SelectItem (javax.faces.model.SelectItem)5 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)4 QuickSort (org.alfresco.web.data.QuickSort)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ResponseWriter (javax.faces.context.ResponseWriter)3 UserTransaction (javax.transaction.UserTransaction)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3