Search in sources :

Example 1 with ImporterService

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

the class FileFolderServiceImplTest method setUp.

@Override
public void setUp() throws Exception {
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    permissionService = serviceRegistry.getPermissionService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    tenantService = (TenantService) ctx.getBean("tenantService");
    cociService = serviceRegistry.getCheckOutCheckInService();
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();
    // authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    // create a test store
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    // create a folder to import into
    workingRootNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "working root"), ContentModel.TYPE_FOLDER).getChildRef();
    // import the test data
    ImporterService importerService = serviceRegistry.getImporterService();
    Location importLocation = new Location(workingRootNodeRef);
    InputStream is = getClass().getClassLoader().getResourceAsStream(IMPORT_VIEW);
    if (is == null) {
        throw new NullPointerException("Test resource not found: " + IMPORT_VIEW);
    }
    Reader reader = new InputStreamReader(is);
    importerService.importView(reader, importLocation, null, null);
    // Load test model
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("org/alfresco/repo/model/filefolder/testModel.xml");
    List<String> labels = new ArrayList<String>();
    bootstrap.setModels(bootstrapModels);
    bootstrap.setLabels(labels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
    workingRootNodeRef1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "working root1"), QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "folder")).getChildRef();
    nodeService.createNode(workingRootNodeRef1, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.ALFRESCO_URI, "node1"), ContentModel.TYPE_CONTENT).getChildRef();
    nodeService.createNode(workingRootNodeRef1, QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "contains1"), QName.createQName(NamespaceService.ALFRESCO_URI, "node2"), ContentModel.TYPE_CONTENT).getChildRef();
    // Make sure we hit the MLTranslationInterceptor, which is part of the Foundation API
    // See MNT-9114: FileFolderService method not registered in MLTranslationInterceptor
    I18NUtil.setContentLocale(Locale.ENGLISH);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) InputStreamReader(java.io.InputStreamReader) DictionaryBootstrap(org.alfresco.repo.dictionary.DictionaryBootstrap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ImporterService(org.alfresco.service.cmr.view.ImporterService) Reader(java.io.Reader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) InputStreamReader(java.io.InputStreamReader) ServiceRegistry(org.alfresco.service.ServiceRegistry) Location(org.alfresco.service.cmr.view.Location)

Example 2 with ImporterService

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

the class Import method execute.

/* (non-Javadoc)
     * @see org.alfresco.tools.Tool#execute()
     */
@Override
protected int execute() throws ToolException {
    ImporterService importer = getServiceRegistry().getImporterService();
    // determine type of import (from zip or file system)
    ImportPackageHandler importHandler;
    int status = 0;
    for (int i = 0; i < context.packageNames.length; i++) {
        importHandler = new ZipHandler(context.getSourceDir(), context.getPackageFile(i), context.encoding);
        try {
            if (context.zipFile[i]) {
                importHandler = new ZipHandler(context.getSourceDir(), context.getPackageFile(i), context.encoding);
            } else {
                importHandler = new FileHandler(context.getSourceDir(), context.getPackageFile(i), context.encoding);
            }
            try {
                ImportBinding binding = new ImportBinding(context.uuidBinding);
                importer.importView(importHandler, context.getLocation(), binding, new ImportProgress());
            } catch (ImporterException e) {
                throw new ToolException("Failed to import package due to " + e.getMessage(), e);
            }
        } catch (Throwable t) {
            status = handleError(t);
        }
    }
    return status;
}
Also used : ImporterException(org.alfresco.service.cmr.view.ImporterException) ImporterService(org.alfresco.service.cmr.view.ImporterService) ImportPackageHandler(org.alfresco.service.cmr.view.ImportPackageHandler) FileImportPackageHandler(org.alfresco.repo.importer.FileImportPackageHandler) ACPImportPackageHandler(org.alfresco.repo.importer.ACPImportPackageHandler)

Aggregations

ImporterService (org.alfresco.service.cmr.view.ImporterService)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 DictionaryBootstrap (org.alfresco.repo.dictionary.DictionaryBootstrap)1 ACPImportPackageHandler (org.alfresco.repo.importer.ACPImportPackageHandler)1 FileImportPackageHandler (org.alfresco.repo.importer.FileImportPackageHandler)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 ImportPackageHandler (org.alfresco.service.cmr.view.ImportPackageHandler)1 ImporterException (org.alfresco.service.cmr.view.ImporterException)1 Location (org.alfresco.service.cmr.view.Location)1