Search in sources :

Example 26 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class ManageTaskDialogCommand method execute.

/**
 * @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
 */
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
    ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
    ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
    ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
    FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
    WorkflowBean wfBean = (WorkflowBean) FacesHelper.getManagedBean(fc, WorkflowBean.BEAN_NAME);
    // setup dialog context from url args in properties map
    String taskId = (String) properties.get(PROP_TASKID);
    ParameterCheck.mandatoryString(PROP_TASKID, taskId);
    String taskType = (String) properties.get(PROP_TASKTYPE);
    ParameterCheck.mandatoryString(PROP_TASKTYPE, taskType);
    wfBean.setupTaskDialog(taskId, taskType);
    NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "dialog:manageTask");
    String viewId = fc.getViewRoot().getViewId();
    try {
        sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
    } catch (Exception e) {
        throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
    }
    return null;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) FacesContext(javax.faces.context.FacesContext) ServletContext(javax.servlet.ServletContext) WorkflowBean(org.alfresco.web.bean.workflow.WorkflowBean) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NavigationHandler(javax.faces.application.NavigationHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 27 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class SearchContext method fromXML.

/**
 * Restore a SearchContext from an XML definition
 *
 * @param xml     XML format SearchContext @see #toXML()
 */
public SearchContext fromXML(String xml) {
    try {
        NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
        // get the root element
        SAXReader reader = new SAXReader();
        Document document = reader.read(new StringReader(xml));
        Element rootElement = document.getRootElement();
        Element textElement = rootElement.element(ELEMENT_TEXT);
        if (textElement != null) {
            this.text = textElement.getText();
        }
        Element modeElement = rootElement.element(ELEMENT_MODE);
        if (modeElement != null) {
            this.mode = Integer.parseInt(modeElement.getText());
        }
        Element locationElement = rootElement.element(ELEMENT_LOCATION);
        if (locationElement != null) {
            this.location = locationElement.getText();
        }
        Element categoriesElement = rootElement.element(ELEMENT_CATEGORIES);
        if (categoriesElement != null) {
            List<String> categories = new ArrayList<String>(4);
            for (Iterator i = categoriesElement.elementIterator(ELEMENT_CATEGORY); i.hasNext(); ) /**/
            {
                Element categoryElement = (Element) i.next();
                categories.add(categoryElement.getText());
            }
            this.categories = categories.toArray(this.categories);
        }
        Element contentTypeElement = rootElement.element(ELEMENT_CONTENT_TYPE);
        if (contentTypeElement != null) {
            this.contentType = contentTypeElement.getText();
        }
        Element folderTypeElement = rootElement.element(ELEMENT_FOLDER_TYPE);
        if (folderTypeElement != null) {
            this.folderType = folderTypeElement.getText();
        }
        Element mimetypeElement = rootElement.element(ELEMENT_MIMETYPE);
        if (mimetypeElement != null) {
            this.mimeType = mimetypeElement.getText();
        }
        Element attributesElement = rootElement.element(ELEMENT_ATTRIBUTES);
        if (attributesElement != null) {
            for (Iterator i = attributesElement.elementIterator(ELEMENT_ATTRIBUTE); i.hasNext(); ) /**/
            {
                Element attrElement = (Element) i.next();
                QName qname = QName.createQName(attrElement.attributeValue(ELEMENT_NAME), ns);
                addAttributeQuery(qname, attrElement.getText());
            }
        }
        Element rangesElement = rootElement.element(ELEMENT_RANGES);
        if (rangesElement != null) {
            for (Iterator i = rangesElement.elementIterator(ELEMENT_RANGE); i.hasNext(); ) /**/
            {
                Element rangeElement = (Element) i.next();
                Element lowerElement = rangeElement.element(ELEMENT_LOWER);
                Element upperElement = rangeElement.element(ELEMENT_UPPER);
                Element incElement = rangeElement.element(ELEMENT_INCLUSIVE);
                if (lowerElement != null && upperElement != null && incElement != null) {
                    QName qname = QName.createQName(rangeElement.attributeValue(ELEMENT_NAME), ns);
                    addRangeQuery(qname, lowerElement.getText(), upperElement.getText(), Boolean.parseBoolean(incElement.getText()));
                }
            }
        }
        Element valuesElement = rootElement.element(ELEMENT_FIXED_VALUES);
        if (valuesElement != null) {
            for (Iterator i = valuesElement.elementIterator(ELEMENT_VALUE); i.hasNext(); ) /**/
            {
                Element valueElement = (Element) i.next();
                QName qname = QName.createQName(valueElement.attributeValue(ELEMENT_NAME), ns);
                addFixedValueQuery(qname, valueElement.getText());
            }
        }
    } catch (Throwable err) {
        throw new AlfrescoRuntimeException("Failed to import SearchContext from XML.", err);
    }
    return this;
}
Also used : NamespaceService(org.alfresco.service.namespace.NamespaceService) SAXReader(org.dom4j.io.SAXReader) QName(org.alfresco.service.namespace.QName) Element(org.dom4j.Element) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Document(org.dom4j.Document)

Example 28 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class Repository method extractMetadata.

/**
 * Extracts the metadata of a "raw" piece of content into a map.
 *
 * @param context Faces Context
 * @param reader Content reader for the source content to extract from
 * @param destination Map of metadata to set metadata values into
 * @return True if an extracter was found
 */
public static boolean extractMetadata(FacesContext context, ContentReader reader, Map<QName, Serializable> destination) {
    // check that source mimetype is available
    String mimetype = reader.getMimetype();
    if (mimetype == null) {
        throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
    }
    // look for a transformer
    MetadataExtracter extracter = getMetadataExtracterRegistry(context).getExtracter(mimetype);
    if (extracter == null) {
        // No metadata extracter is not a failure, but we flag it
        return false;
    }
    try {
        // we have a transformer, so do it
        extracter.extract(reader, destination);
        return true;
    } catch (Throwable e) {
        // it failed
        logger.warn("Metadata extraction failed: \n" + "   reader: " + reader + "\n" + "   extracter: " + extracter);
        return false;
    }
}
Also used : MetadataExtracter(org.alfresco.repo.content.metadata.MetadataExtracter) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 29 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class TransientNode method initNode.

/**
 * Initialises the node.
 *
 * @param data The properties and associations to initialise the node with
 */
protected void initNode(Map<QName, Serializable> data) {
    if (logger.isDebugEnabled())
        logger.debug("Initialising transient node with data: " + data);
    DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
    // marshall the given properties and associations into the internal maps
    this.associations = new QNameNodeMap(this, this);
    this.childAssociations = new QNameNodeMap(this, this);
    if (data != null) {
        // go through all data items and allocate to the correct internal list
        for (QName item : data.keySet()) {
            PropertyDefinition propDef = ddService.getProperty(item);
            if (propDef != null) {
                this.properties.put(item, data.get(item));
            } else {
                // see if the item is either type of association
                AssociationDefinition assocDef = ddService.getAssociation(item);
                if (assocDef != null) {
                    if (assocDef.isChild()) {
                        Object obj = data.get(item);
                        if (obj instanceof NodeRef) {
                            NodeRef child = (NodeRef) obj;
                            // create a child association reference, add it to a list and add the list
                            // to the list of child associations for this node
                            List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
                            ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, child);
                            assocs.add(childRef);
                            this.childAssociations.put(item, assocs);
                        } else if (obj instanceof List) {
                            List targets = (List) obj;
                            List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
                            for (Object target : targets) {
                                if (target instanceof NodeRef) {
                                    NodeRef currentChild = (NodeRef) target;
                                    ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, currentChild);
                                    assocs.add(childRef);
                                }
                            }
                            if (assocs.size() > 0) {
                                this.childAssociations.put(item, assocs);
                            }
                        }
                    } else {
                        Object obj = data.get(item);
                        if (obj instanceof NodeRef) {
                            NodeRef target = (NodeRef) obj;
                            // create a association reference, add it to a list and add the list
                            // to the list of associations for this node
                            List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
                            AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), target);
                            assocs.add(assocRef);
                            this.associations.put(item, assocs);
                        } else if (obj instanceof List) {
                            List targets = (List) obj;
                            List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
                            for (Object target : targets) {
                                if (target instanceof NodeRef) {
                                    NodeRef currentTarget = (NodeRef) target;
                                    AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), currentTarget);
                                    assocs.add(assocRef);
                                }
                            }
                            if (assocs.size() > 0) {
                                this.associations.put(item, assocs);
                            }
                        }
                    }
                }
            }
        }
    }
    // show that the maps have been initialised
    this.propsRetrieved = true;
    this.assocsRetrieved = true;
    this.childAssocsRetrieved = true;
    // setup the list of aspects the node would have
    TypeDefinition typeDef = ddService.getType(this.type);
    if (typeDef == null) {
        throw new AlfrescoRuntimeException("Failed to find type definition: " + this.type);
    }
    // get flat list of all aspects for the type
    List<QName> defaultAspects = new ArrayList<QName>(16);
    getMandatoryAspects(typeDef, defaultAspects);
    this.aspects = new HashSet<QName>(defaultAspects);
    // setup remaining variables
    this.path = null;
    this.locked = Boolean.FALSE;
    this.workingCopyOwner = Boolean.FALSE;
}
Also used : QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class CreateRuleWizard method initialiseConditionHandlers.

/**
 * Initialises the condition handlers from the current configuration.
 */
protected void initialiseConditionHandlers() {
    if ((this.conditionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers");
            if (conditionHandlerCfg != null) {
                this.conditionHandlers = new HashMap<String, IHandler>(20);
                // instantiate each handler and store in the map
                for (ConfigElement child : conditionHandlerCfg.getChildren()) {
                    String conditionName = child.getAttribute("name");
                    String handlerClass = child.getAttribute("class");
                    if (conditionName != null && conditionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
                        try {
                            @SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
                            IHandler handler = (IHandler) klass.newInstance();
                            this.conditionHandlers.put(conditionName, handler);
                        } catch (Exception e) {
                            throw new AlfrescoRuntimeException("Failed to setup condition handler for '" + conditionName + "'", e);
                        }
                    }
                }
            } else {
                logger.warn("Could not find 'condition-handlers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) IHandler(org.alfresco.web.bean.actions.IHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8