use of org.talend.repository.model.IRepositoryService 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.repository.model.IRepositoryService in project tdi-studio-se by Talend.
the class SetupProcessDependenciesRoutinesAction method doRun.
@Override
protected void doRun() {
ISelection selection = getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj == null) {
return;
}
RepositoryNode node = (RepositoryNode) obj;
boolean readonly = false;
IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
ERepositoryStatus status = repFactory.getStatus(node.getObject());
if (!repFactory.isPotentiallyEditable(node.getObject()) || status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
readonly = true;
}
Item item = node.getObject().getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
ProcessType process = processItem.getProcess();
SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
if (dialog.open() == Window.OK && !readonly) {
process.getParameters().getRoutinesParameter().clear();
createRoutinesDependencies(process, dialog.getSystemRoutines());
createRoutinesDependencies(process, dialog.getUserRoutines());
try {
CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(processItem);
RelationshipItemBuilder.getInstance().addOrUpdateItem(processItem);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobProcessItem = (JobletProcessItem) item;
ProcessType process = jobProcessItem.getJobletProcess();
SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
if (dialog.open() == Window.OK && !readonly) {
process.getParameters().getRoutinesParameter().clear();
createRoutinesDependencies(process, dialog.getSystemRoutines());
createRoutinesDependencies(process, dialog.getUserRoutines());
try {
CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(jobProcessItem);
IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (jobletService != null) {
jobletService.loadComponentsFromProviders();
}
RelationshipItemBuilder.getInstance().addOrUpdateItem(jobProcessItem);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.
the class ContextRepositoryReviewDialog method okPressed.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.dialog.RepositoryReviewDialog#okPressed()
*/
@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
if (params == null || params.isEmpty()) {
super.okPressed();
}
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (createNewButton.getSelection()) {
if (nameInvalid(contextNameText)) {
//$NON-NLS-1$
MessageDialog.openError(getShell(), "Context", msg);
return;
} else {
item = PropertiesFactory.eINSTANCE.createContextItem();
if (item == null) {
return;
}
Property createProperty = PropertiesFactory.eINSTANCE.createProperty();
createProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
createProperty.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
createProperty.setStatusCode("");
try {
String nextId = factory.getNextId();
createProperty.setId(nextId);
item.setProperty(createProperty);
for (IContext context : contextManager.getListContext()) {
ContextType contextType = TalendFileFactory.eINSTANCE.createContextType();
contextType.setName(context.getName());
item.getContext().add(contextType);
}
item.setDefaultContext(contextManager.getDefaultContext().getName());
item.getProperty().setLabel(contextNameText.getText().trim());
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory();
try {
boolean nameAvaliabe = repositoryFactory.isNameAvailable(createProperty.getItem(), contextNameText.getText());
if (!nameAvaliabe) {
MessageDialog.openError(getShell(), "Context", //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"PropertiesWizardPage.ItemExistsError"));
return;
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
super.okPressed();
}
//$NON-NLS-1$
factory.create(item, new Path(""));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
super.okPressed();
}
}
} else {
IStructuredSelection selection = (IStructuredSelection) getRepositoryTreeViewer().getSelection();
RepositoryNode context = (RepositoryNode) selection.getFirstElement();
try {
// get the item from file
IRepositoryViewObject contextObj = factory.getLastVersion(context.getObject().getProperty().getId());
item = (ContextItem) contextObj.getProperty().getItem();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
super.okPressed();
}
}
super.okPressed();
}
use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method doSetInput.
@Override
public void doSetInput(IEditorInput input) throws CoreException {
// Lock the process :
IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
if (input instanceof RepositoryEditorInput) {
rEditorInput = (RepositoryEditorInput) input;
} else {
FileEditorInput fileInput = (FileEditorInput) input;
rEditorInput = new RepositoryEditorInput(fileInput.getFile(), rEditorInput.getItem());
}
if (rEditorInput.getRepositoryNode() == null) {
// retrieve node
rEditorInput.setRepositoryNode(null);
}
try {
// see bug 1321
item = (FileItem) rEditorInput.getItem();
if (!rEditorInput.isReadOnly()) {
if (getRepositoryFactory().getStatus(item).isPotentiallyEditable()) {
item.getProperty().eAdapters().add(dirtyListener);
repFactory.lock(item);
}
} else {
rEditorInput.getFile().setReadOnly(true);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
rEditorInput.getFile().refreshLocal(IResource.DEPTH_ONE, null);
super.doSetInput(rEditorInput);
setName();
// only for sql template
if (item instanceof SQLPatternItem) {
Workspace ws = (Workspace) ResourcesPlugin.getWorkspace();
ws.broadcastBuildEvent(item, IResourceChangeEvent.POST_CHANGE, 1);
}
}
use of org.talend.repository.model.IRepositoryService in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method doSave.
@Override
public void doSave(final IProgressMonitor monitor) {
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
repFactory.lock(item);
} catch (Exception e) {
ExceptionHandler.process(e);
}
ERepositoryStatus status = repFactory.getStatus(item);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage.routine"));
return;
}
EList adapters = item.getProperty().eAdapters();
adapters.remove(dirtyListener);
super.doSave(monitor);
try {
resetItem();
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(((FileEditorInput) getEditorInput()).getFile());
final IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
runProcessService.buildJavaProject();
// check syntax error
addProblems();
//$NON-NLS-1$
String name = "Save Routine";
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {
@Override
protected void run() throws LoginException, PersistenceException {
refreshJobAndSave(repFactory);
}
};
repositoryWorkUnit.setAvoidSvnUpdate(true);
repositoryWorkUnit.setAvoidUnloadResources(true);
repFactory.executeRepositoryWorkUnit(repositoryWorkUnit);
repositoryWorkUnit.throwPersistenceExceptionIfAny();
// for bug 11930: Unable to save Routines.* in db project
// repFactory.save(item);
// startRefreshJob(repFactory);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
Aggregations