use of org.talend.core.model.properties.BusinessProcessItem in project tdi-studio-se by Talend.
the class BusinessDiagramEditor method doSave.
@Override
public void doSave(IProgressMonitor progressMonitor) {
if (repositoryEditorInput != null) {
final BusinessProcessItem businessProcessItem = (BusinessProcessItem) repositoryEditorInput.getItem();
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
repFactory.updateLockStatus();
// For TDI-23825, if not lock by user try to lock again.
boolean locked = repFactory.getStatus(businessProcessItem) == ERepositoryStatus.LOCK_BY_USER;
if (!locked) {
repFactory.lock(businessProcessItem);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
ERepositoryStatus status = repFactory.getStatus(businessProcessItem);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditorSite().getShell(), //$NON-NLS-1$
Messages.getString("BusinessDiagramEditor.canNotSaveTitle"), //$NON-NLS-1$
Messages.getString("BusinessDiagramEditor.canNotSaveMessage"));
return;
}
super.doSave(progressMonitor);
DiagramResourceManager diagramResourceManager = new DiagramResourceManager();
diagramResourceManager.updateFromResource(businessProcessItem, repositoryEditorInput.getFile());
final IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
RepositoryWorkUnit rwu = new RepositoryWorkUnit("save Business") {
@Override
protected void run() throws LoginException, PersistenceException {
ProxyRepositoryFactory.getInstance().save(businessProcessItem);
}
};
rwu.setAvoidUnloadResources(true);
rwu.setAvoidSvnUpdate(true);
factory.executeRepositoryWorkUnit(rwu);
propertyIsDirty = false;
firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
use of org.talend.core.model.properties.BusinessProcessItem in project tdi-studio-se by Talend.
the class OpenExistVersionProcessWizard method performFinish.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
if (mainPage.isCreateNewVersionJob()) {
try {
ProxyRepositoryFactory.getInstance().updateLockStatus();
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
ERepositoryStatus repositoryStatus = ProxyRepositoryFactory.getInstance().getStatus(processObject);
if ((repositoryStatus.equals(ERepositoryStatus.READ_ONLY)) || repositoryStatus == ERepositoryStatus.LOCK_BY_OTHER || repositoryStatus.equals(ERepositoryStatus.LOCK_BY_USER)) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(getShell(), "Warning", Messages.getString("OpenExistVersionProcessWizard.labelContent"));
}
});
return false;
} else {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
if (!alreadyEditedByUser) {
refreshNewJob();
RelationshipItemBuilder.getInstance().addOrUpdateItem(processObject.getProperty().getItem());
try {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
try {
Item newCreated = null;
if (processObject.getProperty() != null && processObject.getProperty().getItem() != null) {
newCreated = processObject.getProperty().getItem();
}
if (!(newCreated instanceof BusinessProcessItem)) {
ProxyRepositoryFactory.getInstance().lock(processObject);
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
} catch (LoginException e) {
ExceptionHandler.process(e);
}
boolean locked = processObject.getRepositoryStatus().equals(ERepositoryStatus.LOCK_BY_USER);
openAnotherVersion((RepositoryNode) processObject.getRepositoryNode(), !locked);
try {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace
// runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e);
}
}
} else {
StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
RepositoryNode node = (RepositoryNode) selection.getFirstElement();
boolean lastVersion = node.getObject().getVersion().equals(processObject.getVersion());
// processObject.getProperty().setVersion(originalVersion);
if (lastVersion) {
lockObject(processObject);
}
ERepositoryStatus status = node.getObject().getRepositoryStatus();
boolean isLocked = false;
if (status == ERepositoryStatus.LOCK_BY_USER) {
isLocked = true;
}
// Only latest version can be editted
openAnotherVersion(node, !lastVersion || !isLocked);
}
return true;
}
use of org.talend.core.model.properties.BusinessProcessItem in project tdi-studio-se by Talend.
the class OpenExistVersionProcessWizard method openAnotherVersion.
protected void openAnotherVersion(final RepositoryNode node, final boolean readonly) {
try {
if (node.getObject() != null) {
final Item item = node.getObject().getProperty().getItem();
final IWorkbenchPage page = getActivePage();
final RepositoryEditorInput fileEditorInput = getEditorInput(item, readonly, page);
if (fileEditorInput != null) {
IEditorPart editorPart = page.findEditor(fileEditorInput);
if (editorPart == null) {
fileEditorInput.setRepositoryNode(node);
if (item instanceof ProcessItem) {
page.openEditor(fileEditorInput, MultiPageTalendEditor.ID, readonly);
} else if (item instanceof BusinessProcessItem) {
CorePlugin.getDefault().getDiagramModelService().openBusinessDiagramEditor(page, fileEditorInput);
} else {
ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
//$NON-NLS-1$ //$NON-NLS-2$
String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
page.openEditor(fileEditorInput, talendEditorID);
}
} else {
page.activate(editorPart);
}
} else {
// TDI-19014:open another version of jobScript
if (item instanceof JobScriptItem) {
IProject fsProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
openXtextEditor(node, fsProject, readonly);
}
}
}
} catch (PartInitException e) {
MessageBoxExceptionHandler.process(e);
} catch (SystemException e) {
MessageBoxExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.BusinessProcessItem in project tdi-studio-se by Talend.
the class ChangeXmiSerialization method execute.
@Override
public ExecutionResult execute(Project project) {
try {
if (!project.isLocal()) {
return ExecutionResult.NOTHING_TO_DO;
}
IProject iProject = ResourceUtils.getProject(project);
xmiResourceManager = new XmiResourceManager();
xmiResourceManager.setUseOldProjectFile(true);
if (!xmiResourceManager.hasTalendProjectFile(iProject)) {
return ExecutionResult.NOTHING_TO_DO;
}
PropertiesResourcesCollector propertiesResourcesCollector = new PropertiesResourcesCollector();
iProject.accept(propertiesResourcesCollector);
Collection<IFile> propertiesResourcesFiles = propertiesResourcesCollector.getPropertiesResourcesFiles();
for (IFile file : propertiesResourcesFiles) {
Property property = xmiResourceManager.loadProperty(file);
// we access the author (resolve proxy)
boolean correctAuthor = false;
try {
property.getAuthor();
} catch (Exception e) {
// author is null : fix old bug
correctAuthor = true;
}
if (correctAuthor || property.getAuthor().getLogin() == null) {
property.setAuthor(project.getAuthor());
}
EcoreUtil.resolveAll(property.eResource());
// if .properties is saved then migrated .item must also be saved
if (property.getItem() instanceof BusinessProcessItem) {
BusinessProcessItem businessProcessItem = (BusinessProcessItem) property.getItem();
businessProcessItem.getNotation();
}
modifiedResources.add(property.eResource());
}
Resource projectResource = xmiResourceManager.loadProject(iProject).eResource();
xmiResourceManager.setUseOldProjectFile(false);
Resource newProjectResource = xmiResourceManager.createProjectResource(iProject);
EObject[] objects = (EObject[]) projectResource.getContents().toArray();
for (EObject object : objects) {
newProjectResource.getContents().add(object);
}
modifiedResources.add(newProjectResource);
for (Resource resource : modifiedResources) {
try {
resource.setModified(true);
xmiResourceManager.saveResource(resource);
} catch (PersistenceException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
xmiResourceManager.deleteResource(projectResource);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
Aggregations