use of org.alfresco.repo.action.executer.ImporterActionExecuter in project acs-community-packaging by Alfresco.
the class ImportDialog method performImport.
/**
* Performs the import operation using the current state of the bean
*
* @return The outcome
*/
public String performImport(final FacesContext context, String outcome) {
if (logger.isDebugEnabled())
logger.debug("Called import for file: " + this.file);
if (this.file != null && this.file.exists()) {
// check the file actually has contents
if (this.file.length() > 0) {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// first of all we need to add the uploaded ACP/ZIP file to the repository
NodeRef acpNodeRef = addFileToRepository(context);
// build the action params map based on the bean's current state
Map<String, Serializable> params = new HashMap<String, Serializable>(2, 1.0f);
params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, browseBean.getActionSpace().getNodeRef());
params.put(ImporterActionExecuter.PARAM_ENCODING, encoding);
// build the action to execute
Action action = getActionService().createAction(ImporterActionExecuter.NAME, params);
if (action instanceof ImporterActionExecuter) {
((ImporterActionExecuter) action).setHighByteZip(highByteZip);
}
action.setExecuteAsynchronously(runInBackground);
// execute the action on the ACP file
getActionService().executeAction(action, acpNodeRef);
if (logger.isDebugEnabled()) {
logger.debug("Executed import action with action params of " + params);
}
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the bean
reset();
} catch (Throwable e) {
if (e instanceof DuplicateChildNodeNameException) {
String name = ((DuplicateChildNodeNameException) e).getName();
String err_mess = MessageFormat.format(I18NUtil.getMessage(ERR_DUPLICATE_NAME), name);
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), err_mess), e);
} else {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), e.toString()), e);
}
outcome = null;
ReportedException.throwIfNecessary(e);
}
} else {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_EMPTY_FILE));
outcome = null;
}
} else {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_NO_FILE));
outcome = null;
}
return outcome;
}
Aggregations