use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class AddContextCommentValueMigrationTask method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
EList<ContextType> 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();
} else if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
contexts = contextItem.getContext();
}
// 2 kinds of situation should be excluded before doing migration to the old context:
// 1.has null, 2.all same comment values;
// 1 is from 6.1.0 release and 5.6.2 patched TPS-1109, all null comment value will set to "".
// for repository context in job, won't change anything because the repository context has been fixed
// the update action will execute when opening job.
boolean hasNull = false, isSame = true;
if (contexts != null && contexts.size() > 1) {
List<String> firstComments = new ArrayList<String>();
for (int x = 0; x < contexts.size(); x++) {
List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
for (int y = 0; y < contextParams.size(); y++) {
ContextParameterType param = contextParams.get(y);
boolean isBuiltin = param.getRepositoryContextId() == null;
String comment = param.getComment();
if (comment == null) {
if (isBuiltin) {
//$NON-NLS-1$
param.setComment("");
hasNull = true;
}
continue;
}
// comments to show in old item before 5.6.1 are always in the first group.
if (x == 0) {
if (!isBuiltin) {
//$NON-NLS-1$
firstComments.add("NOT_BUILTIN");
} else {
firstComments.add(comment);
}
continue;
}
if (isBuiltin && !comment.equals(firstComments.get(y))) {
isSame = false;
}
}
}
try {
if (hasNull) {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
if (!isSame) {
for (int x = 1; x < contexts.size(); x++) {
List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
for (int y = 0; y < contextParams.size(); y++) {
ContextParameterType param = contextParams.get(y);
String comment = param.getComment();
if (param.getRepositoryContextId() == null && !firstComments.get(y).equals(comment)) {
if (!firstComments.get(y).equals("NOT_BUILTIN")) {
//$NON-NLS-1$
param.setComment(firstComments.get(y));
}
}
}
}
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class AddMomInputToComponentsListMigrationTask method getFirstMomInput.
private String getFirstMomInput(Item item) {
// TODO Auto-generated method stub
if (item instanceof ProcessItem) {
ProcessType processType = ((ProcessItem) item).getProcess();
for (Object o : processType.getNode()) {
if (o instanceof NodeType) {
NodeType currentNode = (NodeType) o;
if ("tMomInput".equals(currentNode.getComponentName())) {
EList elements = currentNode.getElementParameter();
Iterator iterator = elements.iterator();
while (iterator.hasNext()) {
ElementParameterType elementParameter = (ElementParameterType) iterator.next();
if ("UNIQUE_NAME".equals(elementParameter.getName())) {
return elementParameter.getValue();
}
}
}
}
}
}
return "";
}
use of org.talend.core.model.properties.ProcessItem 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.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class BuildJobHandler method addDQDependencies.
private void addDQDependencies(IFolder parentFolder, List<Item> items) throws Exception {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
ITDQItemService tdqItemService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
for (Item item : items) {
if (tdqItemService != null && tdqItemService.hasProcessItemDependencies(Arrays.asList(new Item[] { item }))) {
setNeedItemDependencies(true);
// add .Talend.definition file
//$NON-NLS-1$
String defIdxFolderName = "TDQ_Libraries";
//$NON-NLS-1$
String defIdxFileName = ".Talend.definition";
Project pro = getProject(processItem);
IFolder itemsProjectFolder = parentFolder.getFolder(pro.getTechnicalLabel().toLowerCase());
File itemsFolderDir = new File(parentFolder.getLocation().toFile().getAbsolutePath());
IProject project = ReponsitoryContextBridge.getRootProject();
String defIdxRelativePath = defIdxFolderName + PATH_SEPARATOR + defIdxFileName;
IFile defIdxFile = project.getFile(defIdxRelativePath);
if (defIdxFile.exists()) {
File defIdxFileSource = new File(project.getLocation().makeAbsolute().append(defIdxFolderName).append(defIdxFileName).toFile().toURI());
File defIdxFileTarget = new File(itemsProjectFolder.getFile(defIdxRelativePath).getLocation().toFile().getAbsolutePath());
FilesUtils.copyFile(defIdxFileSource, defIdxFileTarget);
}
// add report header image & template files
//$NON-NLS-1$
String reportingBundlePath = PluginChecker.getBundlePath("org.talend.dataquality.reporting");
//$NON-NLS-1$
File imageFolder = new File(reportingBundlePath + PATH_SEPARATOR + "images");
if (imageFolder.exists()) {
FilesUtils.copyDirectory(imageFolder, itemsFolderDir);
}
//$NON-NLS-1$
File templateFolder = new File(reportingBundlePath + PATH_SEPARATOR + "reports");
if (templateFolder.exists() && templateFolder.isDirectory()) {
FilesUtils.copyDirectory(templateFolder, itemsFolderDir);
}
}
}
// maven command 'include-survivorship-rules' to export.
if (!isOptionChoosed(ExportChoice.needJobItem)) {
ExportFileResource resouece = new ExportFileResource();
BuildExportManager.getInstance().exportDependencies(resouece, processItem);
if (!resouece.getAllResources().isEmpty()) {
final Iterator<String> relativepath = resouece.getRelativePathList().iterator();
//$NON-NLS-1$
String pathStr = "metadata/survivorship";
IFolder targetFolder = talendProcessJavaProject.getResourcesFolder();
if (targetFolder.exists()) {
IFolder survFolder = targetFolder.getFolder(new Path(pathStr));
// only copy self job rules, clear the 'survivorship' folder before copy.
if (survFolder.exists()) {
survFolder.delete(true, null);
}
while (relativepath.hasNext()) {
String relativePath = relativepath.next();
Set<URL> sources = resouece.getResourcesByRelativePath(relativePath);
for (URL sourceUrl : sources) {
File currentResource = new File(org.talend.commons.utils.io.FilesUtils.getFileRealPath(sourceUrl.getPath()));
if (currentResource.exists()) {
FilesUtils.copyDirectory(currentResource, new File(targetFolder.getLocation().toPortableString() + File.separator + pathStr));
}
}
}
}
}
parentFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
}
}
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class BuildJobHandler method generateTestReports.
@Override
public void generateTestReports(IProgressMonitor monitor) throws Exception {
if (!isOptionChoosed(ExportChoice.includeTestSource)) {
return;
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
List<IFile> reports = new ArrayList<IFile>();
List<ProcessItem> testsItems = testContainerService.getAllTestContainers(processItem);
for (ProcessItem testItem : testsItems) {
List<IFile> testReportFiles = testContainerService.getTestReportFiles(testItem);
if (testReportFiles.size() > 0) {
reports.add(testReportFiles.get(0));
}
}
IFolder testsFolder = talendProcessJavaProject.getTestsFolder();
talendProcessJavaProject.cleanFolder(monitor, testsFolder);
IFolder parentFolder = talendProcessJavaProject.createSubFolder(monitor, testsFolder, processItem.getProperty().getLabel());
for (IFile report : reports) {
report.copy(parentFolder.getFile(report.getName()).getFullPath(), true, monitor);
}
}
}
}
Aggregations