use of org.talend.repository.model.IProxyRepositoryFactory 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.IProxyRepositoryFactory in project tdi-studio-se by Talend.
the class JobletUtil method needReadOnlyJoblet.
public boolean needReadOnlyJoblet(JobletProcessItem jobletItem) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart[] editors = page.getEditors();
for (IEditorPart editor : editors) {
if (editor instanceof AbstractMultiPageTalendEditor) {
List<? extends INode> nodeList = ((AbstractMultiPageTalendEditor) editor).getProcess().getGraphicalNodes();
for (INode node : nodeList) {
if (((Node) node).isJoblet() && jobletItem.getProperty() != null) {
if (jobletItem.getProperty().getId().equals(node.getComponent().getProcess().getId())) {
boolean haveLock = jobletItem.getState().isLocked();
boolean isSvn = false;
ISVNProviderService service = null;
if (PluginChecker.isSVNProviderPluginLoaded()) {
service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
}
if (service != null && service.isProjectInSvnMode()) {
isSvn = service.isProjectInSvnMode();
}
if (isSvn) {
IProxyRepositoryService proxyService = (IProxyRepositoryService) GlobalServiceRegister.getDefault().getService(IProxyRepositoryService.class);
IProxyRepositoryFactory factory = proxyService.getProxyRepositoryFactory();
ERepositoryStatus repositoryStatus = factory.getStatus(jobletItem);
if (repositoryStatus == ERepositoryStatus.LOCK_BY_USER) {
haveLock = true;
}
}
if (haveLock) {
return true;
}
}
}
}
}
}
return false;
}
use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.
the class DbTableController method getExistConnection.
/**
* DOC zli Comment method "getExistConnection".
*
* @return
*/
private DatabaseConnection getExistConnection() {
String implicitRepositoryId = getImplicitRepositoryId();
String statsLogPrositoryId = getStatsLogRepositoryId();
if (implicitRepositoryId != null || statsLogPrositoryId != null) {
// jobsetting view load the exist db info from current selected category
String repId = null;
if (EComponentCategory.EXTRA.equals(section)) {
repId = implicitRepositoryId;
} else if (EComponentCategory.STATSANDLOGS.equals(section)) {
repId = statsLogPrositoryId;
}
if (repId != null) {
IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
try {
IRepositoryViewObject lastVersion = proxyRepositoryFactory.getLastVersion(repId);
if (lastVersion != null) {
Item item = lastVersion.getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnection connection = (DatabaseConnection) ((DatabaseConnectionItem) item).getConnection();
return connection;
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
return null;
}
use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.
the class GenerateGrammarController method persistInRoutine.
/**
* Persist item in routines
*
* DOC ytao Comment method "persistInRoutine".
*
* @param path, sub folder named with job id
* @param label, java file name without suffix
* @param initFile, File handler
* @param name, job id as package name
* @return
*/
private RoutineItem persistInRoutine(IPath inFolder, File fileToFill, String label) {
// item property to be set
Property property = PropertiesFactory.eINSTANCE.createProperty();
property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
property.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
property.setStatusCode("");
// Label must match pattern ^[a-zA-Z\_]+[a-zA-Z0-9\_]*$
// Must be composed with JAVA_PORJECT_NAME + JOB NAME + COMPONENT NAME,
// since all projects share with the same routines
property.setLabel(label);
// add properties to item
RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
routineItem.setProperty(property);
// get the content of java file as byte array.
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
InputStream stream = null;
try {
stream = new FileInputStream(fileToFill);
byte[] bytes = new byte[stream.available()];
stream.read(bytes);
byteArray.setInnerContent(bytes);
} catch (IOException e) {
ExceptionHandler.process(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
routineItem.setContent(byteArray);
// persist item in routines
IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
try {
property.setId(repositoryFactory.getNextId());
// create folder with name job id: routines/JOBID (seems from TOS)
repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), inFolder);
// add the item
repositoryFactory.create(routineItem, inFolder);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return routineItem;
}
use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.
the class ValidationRulesUtil method getComponentsFromItemId.
/**
* DOC ycbai Comment method "getComponentsFromItemId". modify from method getAppropriateComponent() of
* TalendEditorDropTargetListener.
*
* @param itemId
* @param type
* @param quickCreateInput
* @param quickCreateOutput
* @return
*/
public static IComponent getComponentsFromItemId(String itemId, ERepositoryObjectType type, boolean quickCreateInput, boolean quickCreateOutput) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject obj = null;
try {
obj = factory.getLastVersion(itemId);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (obj == null) {
return null;
}
Item item = obj.getProperty().getItem();
if (item == null) {
return null;
}
EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
String componentName = null;
if (item instanceof JobletProcessItem) {
// joblet
componentName = item.getProperty().getLabel();
} else if (name == null) {
return null;
} else {
// tRunjob
componentName = name.getDefaultComponentName();
}
// tRunJob is special from our rules
if (name == EDatabaseComponentName.RunJob || item instanceof JobletProcessItem) {
return ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
} else {
// for database, file, webservices, saleforce ...
List<IComponent> neededComponents = filterNeededComponents(item, type);
IComponent component = chooseOneComponent(neededComponents, name, quickCreateInput, quickCreateOutput);
return component;
}
}
Aggregations