use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class RemoveBinFolderMigrationTask method execute.
@Override
public ExecutionResult execute(Project project) {
XmiResourceManager xmiResourceManager = new XmiResourceManager();
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
for (ERepositoryObjectType type : getTypes()) {
IFolder folder = null;
if (type != null && type.hasFolder()) {
try {
IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
continue;
}
folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource current : ResourceUtils.getMembers(folder)) {
if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
if (fileCurrent instanceof IFile) {
if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
Property property = null;
try {
property = xmiResourceManager.loadProperty(fileCurrent);
} catch (RuntimeException e) {
// property will be null
ExceptionHandler.process(e);
}
if (property != null) {
// restore folder if doesn't exist anymore.
Item propertyItem = property.getItem();
propertyItem.getState().setDeleted(true);
EmfHelper.saveResource(propertyItem.eResource());
String oldPath = propertyItem.getState().getPath();
IPath path = new Path(oldPath);
factory.createParentFoldersRecursively(project, type, path, true);
FolderItem folderItem = factory.getFolderItem(project, type, path);
propertyItem.setParent(folderItem);
String name = fileCurrent.getName().replace(".properties", "");
// take all the files starting by the same name
IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
if (filesToMove.getName().startsWith(name)) {
IPath originalPath = filesToMove.getFullPath();
IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
// if the file exists in both bin and target directory, delete
// the one from bin.
filesToMove.delete(true, new NullProgressMonitor());
} else {
ResourceUtils.moveResource(filesToMove, finalPath);
}
}
}
}
}
}
}
IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
try {
((IFolder) current).delete(true, null);
} catch (CoreException e) {
// not catched, not important if can delete or not
}
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (CoreException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
// }
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class ReadRoutineAction method doRun.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
protected void doRun() {
if (repositoryNode == null && getSelection() != null) {
repositoryNode = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
}
RoutineItem routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
Property updatedProperty = null;
try {
updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(routineItem)), routineItem.getProperty().getId()).getProperty();
// repositoryNode.getObject().setProperty(updatedProperty);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
try {
openRoutineEditor(routineItem, true);
} catch (PartInitException e) {
MessageBoxExceptionHandler.process(e);
} catch (SystemException e) {
MessageBoxExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class DateSection method getCommitDate.
protected Date getCommitDate() {
Property property = getObject().getProperty();
if (property == null || property.getItem() == null) {
return null;
}
Item item = property.getItem();
ItemState state = item.getState();
return state.getCommitDate();
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class BDJobReArchieveCreator method create.
public void create(File file, boolean isExport) {
if (file == null || !file.exists() || (isExport && !file.isFile()) || fatherProcessItem == null) {
return;
}
// check
if (!isMRWithHDInsight() && !isFatJar()) {
return;
}
Property property = processItem.getProperty();
Property fatherProperty = fatherProcessItem.getProperty();
String label = property.getLabel();
String fatherLabel = fatherProperty.getLabel();
String version = property.getVersion();
JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(file.getAbsolutePath(), label);
String jobJarName = JavaResourcesHelper.getJobJarName(property.getLabel(), property.getVersion()) + FileExtensions.JAR_FILE_SUFFIX;
try {
if (isExport) {
// If we are in an export context, we first unzip the archive, then we modify the jar.
// create temp folders.
// clean temp folder
creator.deleteTempFiles();
//$NON-NLS-1$ //$NON-NLS-2$
File zipTmpFolder = new File(creator.getTmpFolder(), "zip-" + label + "_" + version);
//$NON-NLS-1$ //$NON-NLS-2$
File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
zipTmpFolder.mkdirs();
jarTmpFolder.mkdirs();
// unzip the files.
FilesUtils.unzip(file.getAbsolutePath(), zipTmpFolder.getAbsolutePath());
// same the the job pom assembly for package.
File originalJarFile = new File(zipTmpFolder, fatherLabel + '/' + jobJarName);
modifyJar(originalJarFile, jarTmpFolder, creator, jobJarName, zipTmpFolder, property);
ZipToFile.zipFile(zipTmpFolder.getAbsolutePath(), file.getAbsolutePath());
} else {
// If we are in a local context, we just have to modify the jar.
// clean temp folder
creator.deleteTempFiles();
//$NON-NLS-1$ //$NON-NLS-2$
File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
jarTmpFolder.mkdirs();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
File targetFolder = new File(talendProcessJavaProject.getTargetFolder().getLocationURI());
// In a local mode, the routines/beans/udfs jars are not in the lib folder. We then copy them.
// Copy routines and rename it to match the
// "JavaUtils.ROUTINE_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX" name
Set<FilterInfo> codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.ROUTINE_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.ROUTINE_JAR_NAME + //$NON-NLS-1$
FileExtensions.JAR_FILE_SUFFIX));
}
// Copy beans and rename it to match the "JavaUtils.BEANS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
// name
codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.BEANS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.BEANS_JAR_NAME + //$NON-NLS-1$
FileExtensions.JAR_FILE_SUFFIX));
}
// Copy udfs and rename it to match the
// "JavaUtils.PIGUDFS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
// name
codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.PIGUDFS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.PIGUDFS_JAR_NAME + //$NON-NLS-1$
FileExtensions.JAR_FILE_SUFFIX));
}
modifyJar(new File(file, jobJarName), jarTmpFolder, creator, jobJarName, talendProcessJavaProject.getLibFolder().getParent().getLocation().toFile(), property);
} else {
//$NON-NLS-1$
CommonExceptionHandler.log("Unable to update the job jar because the RunProcessService is not registered.");
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
// when debug, keep the files first. because when build again. will do clean also.
if (!CommonsPlugin.isDebugMode()) {
creator.deleteTempFiles();
}
}
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class ChangeValuesFromRepositoryTest method setUp.
/**
* DOC Administrator Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
Property property = PropertiesFactory.eINSTANCE.createProperty();
IProcess2 process = new Process(property);
IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
IComponent targetCom = ComponentsFactoryProvider.getInstance().get("tMysqlOutput", ComponentCategory.CATEGORY_4_DI.getName());
elem = new Node(sourceCom, process);
elem.setLabel("tMysqlInput_1");
target = new Node(targetCom, process);
IMetadataTable table = createSimpleMetadata();
table.setAttachedConnector("FLOW");
List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
metadataList.add(table);
elem.setMetadataList(metadataList);
Connection conn = new Connection(elem, target, EConnectionType.FLOW_MAIN, "FLOW", "metaName", "row1", false);
List<Connection> connList = new ArrayList<Connection>();
connList.add(conn);
target.setIncomingConnections(connList);
elem.setOutgoingConnections(connList);
}
Aggregations