use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.
the class AbstractTDQFileDuplicateHandle method duplicateItem.
/*
* (non-Javadoc)
*
* @see
* org.talend.dataprofiler.core.ui.action.actions.handle.IDuplicateHandle#duplicateItem(org.talend.core.model.properties
* .Item, java.lang.String)
*/
public Item duplicateItem(Item oldItem, String newName) throws BusinessException {
String fileExtension = file.getFileExtension();
IPath newFileNamePath = new Path(newName).addFileExtension(fileExtension);
// IFile newFile = file.getParent().getFile(newFileNamePath);
ModelElement oldModelElement = PropertyHelper.getModelElement(oldItem.getProperty());
IFolder folder = extractFolder(oldItem, oldModelElement);
IFile newFile = folder.getFile(newFileNamePath);
// createt the file item by the duplicated file
Item duplicate = createFileItemByDuplicateFile(newFile, fileExtension, newName);
if (duplicate == null) {
BusinessException createBusinessException = ExceptionFactory.getInstance().createBusinessException(DefaultMessagesImpl.getString("AbstractTDQFileDuplicateHandle.duplicateFail", // $NON-NLS-1$
oldItem.getProperty().getDisplayName()));
throw createBusinessException;
}
return duplicate;
}
use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.
the class TdAddTaskAction method run.
@Override
public void run() {
try {
TdTaskPropertiesDialog dialog = new TdTaskPropertiesDialog(shell);
ModelElement modelElement = null;
if (navObj instanceof RepositoryNode) {
RepositoryNode node = (RepositoryNode) navObj;
modelElement = RepositoryNodeHelper.getModelElementFromRepositoryNode(node);
} else {
modelElement = (ModelElement) navObj;
}
modelElement = (ModelElement) EObjectHelper.resolveObject(modelElement);
if (modelElement == null || modelElement.eResource() == null || modelElement.getName() == null) {
// $NON-NLS-1$
String fileName = "";
if (navObj instanceof RepositoryNode) {
Item item = ((RepositoryNode) navObj).getObject().getProperty().getItem();
if (item instanceof TDQItem) {
fileName = ((TDQItem) item).getFilename();
}
}
throw ExceptionFactory.getInstance().createBusinessException(fileName);
}
IFile file = WorkspaceUtils.getModelElementResource(modelElement);
TdResourceModel tdResModel = new TdResourceModel(file.getFullPath(), (Workspace) file.getWorkspace(), modelElement);
dialog.setResource(tdResModel);
Map<String, Object> attMap = new HashMap<String, Object>();
attMap.put(MarkerViewUtil.NAME_ATTRIBUTE, modelElement.getName());
attMap.put(IMarker.LOCATION, file.getRawLocation().toString());
attMap.put(IMarker.LINE_NUMBER, file.getRawLocation().toString());
dialog.setInitialAttributes(attMap);
dialog.open();
} catch (BusinessException e) {
ExceptionHandler.process(e, Level.FATAL);
} catch (Exception e1) {
log.error(e1, e1);
}
}
use of org.talend.commons.exception.BusinessException in project tdq-studio-se by Talend.
the class ActionHandleFactory method createDuplicateHandle.
public IDuplicateHandle createDuplicateHandle(IRepositoryNode node) throws BusinessException {
IDuplicateHandle handle = null;
EResourceConstant typedConstant = EResourceConstant.getTypedConstant(node.getObject().getProperty().getItem());
if (typedConstant == null) {
BusinessException createBusinessException = ExceptionFactory.getInstance().createBusinessException(// $NON-NLS-1$
DefaultMessagesImpl.getString("ActionHandleFactory.duplicateFail", node.getLabel()));
throw createBusinessException;
} else {
switch(typedConstant) {
case DB_CONNECTIONS:
handle = new DBConnectionDuplicateHandle();
break;
case JRXML_TEMPLATE:
handle = new JrxmlFileDuplicateHandle(node);
break;
case ANALYSIS:
handle = new AnalysisDuplicateHandle();
break;
case REPORTS:
handle = new ReportDuplicateHandle();
break;
case PATTERNS:
case RULES_PARSER:
case RULES_SQL:
case RULES_MATCHER:
handle = new ModelElementDuplicateHandle();
break;
case INDICATORS:
handle = new IndicatorDuplicateHandle();
break;
case SOURCE_FILES:
handle = new SourceFileDuplicateHandle(node);
break;
case CONTEXT:
handle = new ContextDuplicateHandle(node);
default:
break;
}
}
return handle;
}
use of org.talend.commons.exception.BusinessException in project tmdm-studio-se by Talend.
the class RepositoryDropAssistant method moveViewObj.
/**
* DOC hbhong Comment method "moveViewObj".
*
* @param dragViewObj
* @param dropViewObj
* @return
*/
private boolean moveViewObj(IRepositoryViewObject dragViewObj, IRepositoryViewObject dropViewObj) {
if (dropViewObj != null && dragViewObj != null) {
if (RepositoryResourceUtil.isLockedViewObject(dragViewObj)) {
MessageDialog.openError(getShell(), Messages.AbstractRepositoryAction_lockedObjTitle, Messages.RepositoryDropAssistant_stopMoveMsg);
return false;
}
Property dropProp = dropViewObj.getProperty();
String pathStr = dropProp.getItem().getState().getPath();
IPath path = new Path(pathStr);
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
try {
factory.moveObject(dragViewObj, path);
return true;
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
} catch (BusinessException e) {
log.error(e.getMessage(), e);
}
}
return false;
}
use of org.talend.commons.exception.BusinessException in project tmdm-studio-se by Talend.
the class RepositoryDropAssistant method copyViewObj.
public boolean copyViewObj(IRepositoryViewObject dragViewObj, IRepositoryViewObject dropViewObj) {
if (dropViewObj != null && dragViewObj != null) {
Property dragProp = dragViewObj.getProperty();
Property dropProp = dropViewObj.getProperty();
Item item = dragProp.getItem();
String name;
if (item instanceof MDMServerObjectItem) {
MDMServerObject serverObj = ((MDMServerObjectItem) item).getMDMServerObject();
name = serverObj.getName();
} else {
name = dragProp.getLabel();
}
// show dialog
IRepositoryViewObject dragParentViewObj = getParentRepositoryViewObject(dragViewObj);
ContainerItem dragParentItem = (ContainerItem) dragParentViewObj.getProperty().getItem();
// $NON-NLS-1$
String newName = showPasteDlg(dragParentItem.getRepObjType(), dragParentItem, "Copy_" + name);
if (newName != null) {
String pathStr = dropProp.getItem().getState().getPath();
pathStr = rebuildPath(dragViewObj, name, newName, pathStr);
IPath path = new Path(pathStr);
ERepositoryObjectType type = dropViewObj.getRepositoryObjectType();
if (type == IServerObjectRepositoryType.TYPE_WORKFLOW) {
if (exAdapter != null) {
return exAdapter.copyWorkflowViewObj(item, name, newName);
}
} else {
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
Item copy = null;
try {
copy = factory.copy(item, path, true);
if (factory.isEditableAndLockIfPossible(copy)) {
if (copy instanceof MDMServerObjectItem) {
((MDMServerObjectItem) copy).getMDMServerObject().setName(newName);
((MDMServerObjectItem) copy).getMDMServerObject().setLastServerDef(null);
CommandManager.getInstance().pushCommand(ICommand.CMD_ADD, copy.getProperty().getId(), newName);
}
copy.getProperty().setLabel(newName);
copy.getProperty().setDisplayName(newName);
RepositoryResourceUtil.setLastServerDef(copy, null);
factory.save(copy);
MDMRepositoryView.show().refreshRootNode(type);
return true;
}
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
} catch (BusinessException e) {
log.error(e.getMessage(), e);
} finally {
try {
factory.unlock(copy);
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
} catch (LoginException e) {
log.error(e.getMessage(), e);
}
}
}
}
}
return false;
}
Aggregations