Search in sources :

Example 11 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ViewParser method processStartReference.

/**
 * Process start reference
 *
 * @param xpp XmlPullParser
 * @param refName QName
 * @param parserContext ParserContext
 * @throws XmlPullParserException
 * @throws IOException
 */
private void processStartReference(XmlPullParser xpp, QName refName, ParserContext parserContext) throws XmlPullParserException, IOException {
    ParentContext parent = (ParentContext) parserContext.elementStack.peek();
    NodeContext node = new NodeContext(refName, parent, null);
    node.setReference(true);
    // Extract Import scoped reference Id if explicitly defined
    String idRefAttr = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_IDREF_ATTR);
    String pathRefAttr = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_PATHREF_ATTR);
    String nodeRefAttr = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_NODEREF_ATTR);
    if ((idRefAttr != null && idRefAttr.length() > 0) && (pathRefAttr != null && pathRefAttr.length() > 0) && (nodeRefAttr != null && nodeRefAttr.length() > 0)) {
        // Do not support both IDREF and PATHREF
        throw new ImporterException("Only one of " + VIEW_IDREF_ATTR + " or " + VIEW_PATHREF_ATTR + " or " + VIEW_NODEREF_ATTR + " can be specified.");
    }
    // Convert to Node Reference
    NodeRef nodeRef = null;
    if (nodeRefAttr != null) {
        nodeRef = new NodeRef(nodeRefAttr);
    } else if (idRefAttr != null && idRefAttr.length() > 0) {
        // retrieve uuid from previously imported node
        nodeRef = getImportReference(parserContext, idRefAttr);
        if (nodeRef == null) {
            throw new ImporterException("Cannot find node referenced by id " + idRefAttr);
        }
    } else if (pathRefAttr != null && pathRefAttr.length() > 0) {
        nodeRef = parserContext.importer.resolvePath(pathRefAttr);
        if (nodeRef == null) {
            throw new ImporterException("Cannot find node referenced by path " + pathRefAttr);
        }
    }
    // Establish node definition
    node.setUUID(nodeRef.getId());
    node.setTypeDefinition(dictionaryService.getType(nodeService.getType(nodeRef)));
    Set<QName> aspects = nodeService.getAspects(nodeRef);
    for (QName aspect : aspects) {
        node.addAspect(dictionaryService.getAspect(aspect));
    }
    // Extract child name if explicitly defined
    String childName = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_CHILD_NAME_ATTR);
    if (childName != null && childName.length() > 0) {
        node.setChildName(childName);
    }
    // Extract import id if explicitly defined
    String importId = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_ID_ATTR);
    if (importId != null && importId.length() > 0) {
        node.setImportId(importId);
    }
    parserContext.elementStack.push(node);
    if (logger.isDebugEnabled())
        logger.debug(indentLog("Pushed Reference " + node, parserContext.elementStack.size() - 1));
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName)

Example 12 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ImporterBootstrap method getReader.

/**
 * Get a Reader onto an XML view
 *
 * @param view  the view location
 * @param encoding  the encoding of the view
 * @return  the reader
 */
private Reader getReader(String view, String encoding) {
    // Get Input Stream
    ResourceLoader resourceLoader = new DefaultResourceLoader(getClass().getClassLoader());
    Resource viewResource = resourceLoader.getResource(view);
    if (viewResource == null) {
        throw new ImporterException("Could not find view file " + view);
    }
    // Wrap in buffered reader
    try {
        InputStream viewStream = viewResource.getInputStream();
        InputStreamReader inputReader = (encoding == null) ? new InputStreamReader(viewStream) : new InputStreamReader(viewStream, encoding);
        BufferedReader reader = new BufferedReader(inputReader);
        return reader;
    } catch (UnsupportedEncodingException e) {
        throw new ImporterException("Could not create reader for view " + view + " as encoding " + encoding + " is not supported");
    } catch (IOException e) {
        throw new ImporterException("Could not open resource for view " + view);
    }
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 13 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ACPImportPackageHandler method importStream.

/* (non-Javadoc)
     * @see org.alfresco.service.cmr.view.ImportStreamHandler#importStream(java.lang.String)
     */
public InputStream importStream(String content) {
    ZipArchiveEntry zipEntry = zipFile.getEntry(content);
    if (zipEntry == null) {
        // Note: for some reason, when modifying a zip archive the path seperator changes
        // TODO: Need to investigate further as to why and whether this workaround is enough
        content = content.replace('\\', '/');
        zipEntry = zipFile.getEntry(content);
        if (zipEntry == null) {
            throw new ImporterException("Failed to find content " + content + " within zip package");
        }
    }
    try {
        return zipFile.getInputStream(zipEntry);
    } catch (IOException e) {
        throw new ImporterException("Failed to open content " + content + " within zip package due to " + e.getMessage(), e);
    }
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) IOException(java.io.IOException)

Example 14 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class ImporterComponent method getNodeRef.

/**
 * Get Node Reference from Location
 *
 * @param location the location to extract node reference from
 * @param binding import configuration
 * @return node reference
 */
private NodeRef getNodeRef(Location location, ImporterBinding binding) {
    ParameterCheck.mandatory("Location", location);
    // Establish node to import within
    NodeRef nodeRef = location.getNodeRef();
    if (nodeRef == null) {
        // If a specific node has not been provided, default to the root
        nodeRef = nodeService.getRootNode(location.getStoreRef());
    }
    // Resolve to path within node, if one specified
    String path = location.getPath();
    if (path != null && path.length() > 0) {
        // Create a valid path and search
        path = bindPlaceHolder(path, binding);
        path = createValidPath(path);
        List<NodeRef> nodeRefs = searchService.selectNodes(nodeRef, path, null, namespaceService, false);
        if (nodeRefs.size() == 0) {
            throw new ImporterException("Path " + path + " within node " + nodeRef + " does not exist - the path must resolve to a valid location");
        }
        if (nodeRefs.size() > 1) {
            throw new ImporterException("Path " + path + " within node " + nodeRef + " found too many locations - the path must resolve to one location");
        }
        nodeRef = nodeRefs.get(0);
    }
    return nodeRef;
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 15 with ImporterException

use of org.alfresco.service.cmr.view.ImporterException in project alfresco-repository by Alfresco.

the class SystemInfoBootstrap method bootstrap.

/**
 * Bootstrap
 */
public void bootstrap() {
    UserTransaction userTransaction = transactionService.getUserTransaction();
    authenticationContext.setSystemUserAsCurrentUser();
    try {
        userTransaction.begin();
        // check the repository exists, create if it doesn't
        if (performBootstrap()) {
            InputStream viewStream = getClass().getClassLoader().getResourceAsStream(bootstrapView);
            if (viewStream == null) {
                throw new ImporterException("Could not find system info file " + bootstrapView);
            }
            try {
                systemImporter.importSystem(viewStream);
            } finally {
                viewStream.close();
            }
        }
        userTransaction.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (userTransaction != null) {
                userTransaction.rollback();
            }
        } catch (Exception ex) {
        }
        try {
            authenticationContext.clearCurrentSecurityContext();
        } catch (Exception ex) {
        }
        throw new AlfrescoRuntimeException("System Info Bootstrap failed", e);
    } finally {
        authenticationContext.clearCurrentSecurityContext();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) ImporterException(org.alfresco.service.cmr.view.ImporterException) InputStream(java.io.InputStream) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ImporterException(org.alfresco.service.cmr.view.ImporterException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

ImporterException (org.alfresco.service.cmr.view.ImporterException)15 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 QName (org.alfresco.service.namespace.QName)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 Reader (java.io.Reader)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 UserTransaction (javax.transaction.UserTransaction)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ACPImportPackageHandler (org.alfresco.repo.importer.ACPImportPackageHandler)1