use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class RemoveDuplicatedContextGroupMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
List<?> contexts = null;
if (item instanceof ProcessItem) {
// process, process_mr, process_storm, route, routelet.
ProcessItem processItem = (ProcessItem) item;
contexts = processItem.getProcess().getContext();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
contexts = jobletItem.getJobletProcess().getContext();
}
Set<String> nameSet = new HashSet<String>();
Iterator<?> iterator = contexts.listIterator();
int count = 0;
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextType) {
ContextType context = (ContextType) obj;
if (nameSet.contains(context.getName())) {
iterator.remove();
count++;
} else {
nameSet.add(context.getName());
}
}
}
if (count > 0) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class RemoveProjectLibsFolder method execute.
/*
* (non-Javadoc)
*
* @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
*/
@Override
public ExecutionResult execute(Project project) {
String libsFolderName = "libs";
IFolder libsF = null;
try {
IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
libsF = fsProject.getFolder(libsFolderName);
if (!libsF.exists()) {
return ExecutionResult.NOTHING_TO_DO;
}
final IPath location = libsF.getLocation();
libsFolder = new File(location.toPortableString());
ShareProjectLibsMigration migration = new ShareProjectLibsMigration();
migration.shareLibs(null, new NullProgressMonitor());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
try {
libsF.delete(true, new NullProgressMonitor());
} catch (CoreException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class RemoveUnuseQuoteOnTLoop method execute.
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
//$NON-NLS-1$
String[] componentsName = new String[] { "tLoop" };
IComponentConversion removeQuote = new IComponentConversion() {
private void removeQuote(ElementParameterType element) {
if (element != null && element.getValue() != null) {
String dValue = element.getValue();
if (dValue.startsWith("\"") && dValue.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
dValue = dValue.substring(1, dValue.length() - 1);
element.setValue(dValue);
}
}
}
@Override
public void transform(NodeType node) {
//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
List<String> parameters = Arrays.asList(new String[] { "DECLARATION", "CONDITION", "ITERATION" });
for (String parameter : parameters) {
removeQuote(ComponentUtilities.getNodeProperty(node, parameter));
}
}
};
for (String name : componentsName) {
IComponentFilter filter = new NameComponentFilter(name);
try {
ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(removeQuote));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class RenamePasswordParaForLdapMigrationTask method renamePasswordName.
private void renamePasswordName(Item item) {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
ProcessType processType = getProcessType(item);
for (Object object : processType.getNode()) {
if (object instanceof NodeType) {
NodeType currentNode = (NodeType) object;
if (currentNode.getComponentName().startsWith("tLDAP")) {
//$NON-NLS-1$
for (Object o : currentNode.getElementParameter()) {
ElementParameterType para = (ElementParameterType) o;
if ("PASSWD".equals(para.getName())) {
//$NON-NLS-1$
//$NON-NLS-1$
para.setName("PASS");
modified = true;
break;
}
}
}
}
}
if (modified) {
try {
factory.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class RenameSchemaParameterForMSSqlConnectionMigrationTask method renamePasswordName.
private void renamePasswordName(Item item) {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean modified = false;
ProcessType processType = getProcessType(item);
for (Object object : processType.getNode()) {
if (object instanceof NodeType) {
NodeType currentNode = (NodeType) object;
if (currentNode.getComponentName().startsWith("tMSSqlConnection")) {
//$NON-NLS-1$
for (Object o : currentNode.getElementParameter()) {
ElementParameterType para = (ElementParameterType) o;
if ("DB_SCHEMA".equals(para.getName())) {
//$NON-NLS-1$
//$NON-NLS-1$
para.setName("SCHEMA_DB");
modified = true;
break;
}
}
}
}
}
if (modified) {
try {
factory.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
Aggregations