use of org.talend.commons.runtime.model.repository.ERepositoryStatus 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.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method doSave.
/**
* Saves the multi-page editor's document.
*/
@Override
public void doSave(final IProgressMonitor monitor) {
Item curItem = getProcess().getProperty().getItem();
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
// For TDI-23825, if not lock by user try to lock again.
if (!getProcess().isReadOnly()) {
repFactory.lock(curItem);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
if (getProcess().isReadOnly() || repFactory.isUserReadOnlyOnCurrentProject()) {
MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.readonly"), Messages.getString("AbstractMultiPageTalendEditor.readonlyMessage"));
return;
}
ERepositoryStatus status = repFactory.getStatus(curItem);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage"));
return;
}
if (!isDirty()) {
return;
}
Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
changeCollapsedState(true, jobletMap);
updateRunJobContext();
designerEditor.getProcess().getProperty().eAdapters().remove(dirtyListener);
repFactory.addRepositoryWorkUnitListener(repositoryWorkListener);
if (jobletEditor == getActiveEditor()) {
boolean isDirty = jobletEditor.isDirty();
refreshPropertyDirtyStatus();
jobletEditor.doSave(monitor);
try {
IProcess2 oldProcess = getProcess();
ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
ProcessType processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
IProcess2 newProcess = null;
Item item = getProcess().getProperty().getItem();
if (item instanceof ProcessItem) {
((Process) designerEditor.getProcess()).updateProcess(processType);
if (isDirty) {
getProcess().setProcessModified(true);
getProcess().setNeedRegenerateCode(true);
}
} else if (item instanceof JobletProcessItem) {
AbstractProcessProvider processProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
if (processProvider != null) {
newProcess = processProvider.buildNewGraphicProcess(item);
}
designerEditor.setProcess(newProcess);
Boolean lastVersion = null;
if (oldProcess instanceof ILastVersionChecker) {
lastVersion = ((ILastVersionChecker) oldProcess).isLastVersion(item);
}
if (designerEditor.getEditorInput() instanceof JobEditorInput) {
((JobEditorInput) designerEditor.getEditorInput()).checkInit(lastVersion, null, true);
}
}
getEditor(0).doSave(monitor);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
} else {
refreshPropertyDirtyStatus();
getEditor(0).doSave(monitor);
}
/*
* refresh should be executed before add the listener,or it will has eProxy on the property,it will cause a
* editor dirty problem. hywang commet bug 17357
*/
if (processEditorInput != null) {
propertyInformation = new ArrayList(processEditorInput.getItem().getProperty().getInformations());
propertyIsDirty = false;
}
if (designerEditor != null && dirtyListener != null) {
designerEditor.getProcess().getProperty().eAdapters().add(dirtyListener);
}
refreshJobSettingsView();
changeCollapsedState(false, jobletMap);
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
testContainerService.updateDetect(getProcess(), false);
}
}
if (isCheckout) {
CommandStack stack = (CommandStack) getAdapter(CommandStack.class);
stack.flush();
isCheckout = false;
}
}
use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.
the class VersionManagementPage method filterRepositoryNode.
@Override
protected boolean filterRepositoryNode(RepositoryNode node) {
if (node == null) {
return false;
}
if (node.isBin()) {
return false;
}
if (node.getObject() != null) {
ERepositoryStatus status = FACTORY.getStatus(node.getObject());
if (status == ERepositoryStatus.LOCK_BY_OTHER || (status == ERepositoryStatus.LOCK_BY_USER && RepositoryManager.isOpenedItemInEditor(node.getObject()))) {
return false;
}
// table
if (node.getObject() instanceof org.talend.core.model.metadata.MetadataTable) {
return false;
}
// opened items
// TODO
ERepositoryObjectType objectType = node.getObjectType();
if (objectType == ERepositoryObjectType.SQLPATTERNS || objectType == ERepositoryObjectType.ROUTINES) {
RepositoryNode systemNode = node.getParent();
if (systemNode != null) {
// for system folder
if (systemNode.getType() == ENodeType.STABLE_SYSTEM_FOLDER && systemNode.getLabel().equalsIgnoreCase(RepositoryConstants.SYSTEM_DIRECTORY)) {
return false;
}
}
}
if (node.getObject().isDeleted()) {
return false;
}
}
ERepositoryObjectType contentType = node.getContentType();
if (contentType != null) {
if (contentType == ERepositoryObjectType.REFERENCED_PROJECTS || contentType == ERepositoryObjectType.GENERATED) {
return false;
} else if (contentType == ERepositoryObjectType.SQLPATTERNS || contentType == ERepositoryObjectType.ROUTINES) {
// for system folder
if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER && node.getLabel().equalsIgnoreCase(RepositoryConstants.SYSTEM_DIRECTORY)) {
return false;
}
} else // filter tdm items
if (contentType == ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "HIERARCHICAL_MAPPER")) {
return false;
}
}
// for sub folder in db connection
if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
RepositoryNode parentNode = node.getParent();
if (parentNode != null) {
if (parentNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
return false;
}
}
}
return true;
}
use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.
the class JobletConnectionReconnectCommand method execute.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute() {
metadataChanges.clear();
if (newSource != null) {
INodeConnector connector = oldSource.getConnectorFromName(connectorName);
if (connector != null) {
connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() - 1);
connector = newSource.getConnectorFromName(connectorName);
if (connector != null) {
connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
}
}
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
newSourceSchemaType = (String) newSource.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
boolean builtInNewSource = newSource.getConnectorFromName(connectorName).isMultiSchema();
boolean builtInOldSource = oldSource.getConnectorFromName(connectorName).isMultiSchema();
if ((!builtInNewSource) && (!builtInOldSource)) {
setSchemaToNotBuiltInNode(oldSource, newSource, oldMetadataTable);
if (newSource.getJobletNode() != null) {
connection.setMetaName(newSource.getJobletNode().getUniqueName());
} else
connection.setMetaName(newSource.getUniqueName());
} else {
if (!builtInNewSource) {
int num = 0;
for (int i = 0; i < oldSource.getMetadataList().size(); i++) {
IMetadataTable meta = oldSource.getMetadataList().get(i);
if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
num = i;
}
}
oldSource.getMetadataList().remove(num);
setSchemaToNotBuiltInNode(oldSource, newSource, oldMetadataTable);
if (newSource.getJobletNode() != null) {
connection.setMetaName(newSource.getJobletNode().getUniqueName());
} else
connection.setMetaName(newSource.getUniqueName());
}
if (!builtInOldSource) {
IMetadataTable meta = oldMetadataTable.clone();
meta.setTableName(connection.getUniqueName());
newSource.getMetadataList().add(meta);
connection.setMetaName(meta.getTableName());
}
if ((builtInOldSource) && (builtInNewSource)) {
int num = 0;
for (int i = 0; i < oldSource.getMetadataList().size(); i++) {
IMetadataTable meta = oldSource.getMetadataList().get(i);
if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
num = i;
}
}
oldSource.getMetadataList().remove(num);
newSource.getMetadataList().add(oldMetadataTable);
}
}
if (newSourceSchemaType != null) {
newSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
}
if (oldSourceSchemaType != null) {
oldSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
}
} else {
if (newSource.getJobletNode() != null) {
connection.setMetaName(newSource.getJobletNode().getUniqueName());
} else
connection.setMetaName(newSource.getUniqueName());
}
connection.reconnect(newSource, oldTarget, newLineStyle);
connection.updateName();
if (newSourceSchemaType != null && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA) && connector != null) {
IMetadataTable sourceMetadataTable = newSource.getMetadataFromConnector(connector.getName());
// IMetadataTable targetMetadataTable = oldTarget.getMetadataFromConnector(connector.getName());
if (oldMetadataTable != null && sourceMetadataTable != null) {
boolean sameFlag = oldMetadataTable.sameMetadataAs(sourceMetadataTable, IMetadataColumn.OPTIONS_NONE);
// For the auto propagate.
if (!sameFlag && oldTarget.getComponent().isSchemaAutoPropagated() && (oldMetadataTable.getListColumns().isEmpty() || getPropagateDialog())) {
ChangeMetadataCommand changeMetadataCmd = new ChangeMetadataCommand(oldTarget, null, null, sourceMetadataTable);
changeMetadataCmd.execute(true);
metadataChanges.add(changeMetadataCmd);
}
}
}
// ((Process) newSource.getProcess()).checkStartNodes();
// ((Process) newSource.getProcess()).checkProcess();
} else if (newTarget != null) {
newTargetSchemaType = (String) newTarget.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
INodeConnector connector = oldTarget.getConnectorFromType(oldLineStyle);
connector.setCurLinkNbInput(connector.getCurLinkNbInput() - 1);
connector = newTarget.getConnectorFromType(newLineStyle);
connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
connection.reconnect(oldSource, newTarget, newLineStyle);
connection.updateName();
if (newTargetSchemaType != null) {
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA) && !connection.getLineStyle().equals(EConnectionType.FLOW_REF)) {
IMetadataTable targetOldMetadataTable = newTarget.getMetadataFromConnector(connector.getName());
if (oldMetadataTable != null && targetOldMetadataTable != null) {
boolean sameFlag = oldMetadataTable.sameMetadataAs(targetOldMetadataTable, IMetadataColumn.OPTIONS_NONE);
if (newTarget.getJobletNode() != null) {
IProcess2 jobletProcess = (IProcess2) newTarget.getJobletNode().getComponent().getProcess();
ERepositoryStatus status = ProxyRepositoryFactory.getInstance().getStatus(jobletProcess.getProperty().getItem());
if (!status.equals(ERepositoryStatus.READ_ONLY)) {
// For the auto propagate.
if (!sameFlag && newTarget.getComponent().isSchemaAutoPropagated() && (targetOldMetadataTable.getListColumns().isEmpty() || getPropagateDialog())) {
ChangeMetadataCommand changeMetadataCmd = new ChangeMetadataCommand(newTarget, null, null, oldMetadataTable);
changeMetadataCmd.execute(true);
metadataChanges.add(changeMetadataCmd);
}
}
}
}
}
newTarget.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
}
// ((Process) oldTarget.getProcess()).checkStartNodes();
// ((Process) oldTarget.getProcess()).checkProcess();
} else {
//$NON-NLS-1$
throw new IllegalStateException("Should not happen");
}
}
use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tmdm-studio-se by Talend.
the class RepositoryResourceUtilTest method testIsLockedItem.
@Test
public void testIsLockedItem() {
Item mockItem = mock(Item.class);
IProxyRepositoryFactory repositoryFactory = mock(IProxyRepositoryFactory.class);
when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
when(repositoryFactory.getStatus(mockItem)).thenReturn(ERepositoryStatus.LOCK_BY_OTHER);
boolean islockedViewObject = RepositoryResourceUtil.isLockedItem(mockItem);
assertTrue(islockedViewObject);
when(repositoryFactory.getStatus(mockItem)).thenReturn(ERepositoryStatus.LOCK_BY_USER);
islockedViewObject = RepositoryResourceUtil.isLockedItem(mockItem);
assertTrue(islockedViewObject);
// false
ERepositoryStatus[] statuss = { ERepositoryStatus.DEFAULT, ERepositoryStatus.DELETED, ERepositoryStatus.EDITABLE, ERepositoryStatus.ERROR, ERepositoryStatus.NEW, ERepositoryStatus.NOT_UP_TO_DATE, ERepositoryStatus.READ_ONLY, ERepositoryStatus.WARN };
for (ERepositoryStatus status : statuss) {
when(repositoryFactory.getStatus(mockItem)).thenReturn(status);
islockedViewObject = RepositoryResourceUtil.isLockedItem(mockItem);
assertFalse(islockedViewObject);
}
}
Aggregations