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);
}
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;
}
Aggregations