use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.
the class OpenDiagramAction method doRun.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
protected void doRun() {
ISelection selection = getSelectedObject();
if (selection == null) {
return;
}
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof RepositoryNode) {
RepositoryNode repositoryNode = (RepositoryNode) obj;
IRepositoryViewObject repositoryObject = repositoryNode.getObject();
Property updatedProperty = null;
if (repositoryObject instanceof RepositoryObject) {
RepositoryViewObject abstractRepositoryObject = new RepositoryViewObject(repositoryObject.getProperty());
updatedProperty = abstractRepositoryObject.getProperty();
} else if (repositoryObject instanceof RepositoryViewObject) {
updatedProperty = repositoryObject.getProperty();
}
if (updatedProperty != null) {
BusinessProcessItem businessProcessItem = (BusinessProcessItem) updatedProperty.getItem();
DiagramResourceManager diagramResourceManager = new DiagramResourceManager(getActivePage(), new NullProgressMonitor());
IFile file = diagramResourceManager.createDiagramFile();
diagramResourceManager.updateResource(businessProcessItem, file);
IEditorPart part = diagramResourceManager.openEditor(businessProcessItem, file, false);
if (part instanceof BusinessDiagramEditor) {
((BusinessDiagramEditor) part).setLastVersion(true);
}
// TDI-21143 : Studio repository view : remove all refresh call to repo view
// IRepositoryView view = getViewPart();
// if (view != null) {
// view.refresh(repositoryNode);
// }
}
}
}
use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.
the class ImportDemoProjectItemsPage method populateExistItemRecords.
private String populateExistItemRecords(final List<ResourcesManager> manager) {
//$NON-NLS-1$
String messageInfo = "";
final Collection<ImportItem> items = new ArrayList<ImportItem>();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
for (ResourcesManager rm : manager) {
items.addAll(importManager.populateImportingItems(rm, true, monitor));
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
};
try {
new ProgressMonitorDialog(getShell()).run(true, true, op);
} catch (Exception e) {
// ignore me
}
for (ImportItem itemRecord : items) {
if (itemRecord.getExistingItemWithSameId() != null && itemRecord.getExistingItemWithSameId() instanceof RepositoryViewObject) {
RepositoryViewObject reObject = (RepositoryViewObject) itemRecord.getExistingItemWithSameId();
if (itemRecord.getProperty() != null && reObject != null) {
if (!itemRecord.getProperty().getId().equals(reObject.getId()) && itemRecord.getProperty().getLabel().equalsIgnoreCase(reObject.getLabel())) {
messageInfo = Messages.getString("ImportDemoProjectPage.loseItems", reObject.getLabel());
}
if (itemRecord.getProperty().getId().equals(reObject.getId()) && itemRecord.getProperty().getLabel().equals(reObject.getLabel())) {
messageInfo = Messages.getString("ImportDemoProjectPage.overwriteItems");
}
}
}
}
return messageInfo;
}
use of org.talend.core.model.repository.RepositoryViewObject in project tesb-studio-se by Talend.
the class OpenWSDLPage method finish.
public boolean finish() {
// changed by hqzhang for TDI-19527, label=displayName
final String label = item.getProperty().getDisplayName();
item.getProperty().setLabel(label);
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(final IProgressMonitor monitor) throws CoreException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
if (creation) {
item.getProperty().setId(factory.getNextId());
factory.create(item, getDestinationPath());
repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
}
((ServiceConnection) item.getConnection()).setWSDLPath(path);
((ServiceConnection) item.getConnection()).getServicePort().clear();
final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
final InputStream is;
if (null == path) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// create new WSDL file from template
TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
is = new ByteArrayInputStream(baos.toByteArray());
} else {
//$NON-NLS-1$
String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
String filename = wsdl.getKey();
IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
if (!importedWsdl.exists()) {
importedWsdl.create(wsdl.getValue(), true, monitor);
} else {
importedWsdl.setContents(wsdl.getValue(), 0, monitor);
}
createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
}
}
// store WSDL in service
if (!fileWsdl.exists()) {
fileWsdl.create(is, true, monitor);
} else {
fileWsdl.setContents(is, 0, monitor);
}
// create reference to wsdl
//$NON-NLS-1$
createReferenceResources("wsdl");
// path
definition = WSDLUtils.getDefinition(fileWsdl);
populateModelFromWsdl(factory, definition, item, repositoryNode);
factory.save(item);
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
//delete the node if any exception during the creation
if (creation) {
try {
factory.save(item);
factory.deleteObjectPhysical(repositoryNode.getObject());
} catch (PersistenceException e1) {
throw getCoreException("WDSL creation failed", e1);
}
}
//throw the exception
if (e instanceof CoreException) {
throw (CoreException) e;
}
if (e instanceof InvocationTargetException) {
throw getCoreException("WDSL creation failed", e.getCause());
}
throw getCoreException("WDSL creation failed", e);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
// we use the workspace scheduling rule to lock all
ISchedulingRule schedulingRule = workspace.getRoot();
// workspace modifications during the run.
// the update of 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);
return false;
}
// open wsdl editor
OpenWSDLEditorAction action = new OpenWSDLEditorAction();
action.setServiceItem(item);
action.run();
// import schemas if required
if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
try {
getContainer().run(true, true, publishMetadataRunnable);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
setErrorMessage("Populate schema to repository: " + message);
return false;
} catch (InterruptedException e) {
return false;
}
}
return true;
}
use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.
the class DBTreeProvider method convert.
private void convert(Container fromModel, RepositoryNode parent, ERepositoryObjectType type) {
if (fromModel.isEmpty()) {
return;
}
for (Object obj : fromModel.getSubContainer()) {
Container container = (Container) obj;
Folder folderRepositoryObject = new Folder(container.getId(), container.getLabel());
FolderRepositoryObject oFolder = new FolderRepositoryObject(folderRepositoryObject);
oFolder.setImage(IMAGES_CLOSED_FOLDER);
oFolder.setSourceName(oFolder.getLabel());
oFolder.setRepositoryName(null);
RepositoryNode folder = new RepositoryNodeExt(oFolder, parent, ENodeType.SIMPLE_FOLDER);
folder.setProperties(EProperties.LABEL, container.getLabel());
// ERepositoryObjectType.FOLDER);
folder.setProperties(EProperties.CONTENT_TYPE, RepositoryNodeType.FOLDER);
parent.getChildren().add(folder);
convert(container, folder, type);
}
if (!isCleared) {
maps.clear();
isCleared = true;
}
for (Object obj : fromModel.getMembers()) {
RepositoryObject obj2 = (RepositoryObject) obj;
if (!connectionParameters.getRepositoryId().equals(obj2.getProperty().getId())) {
continue;
}
RepositoryViewObject viewObject = new RepositoryViewObject(obj2.getProperty());
maps.put((obj2).getId(), viewObject);
addNode(parent, viewObject, false, null);
}
}
use of org.talend.core.model.repository.RepositoryViewObject in project tdi-studio-se by Talend.
the class GenericDragAndDropHandler method isValid.
private boolean isValid(RepositoryNode seletetedNode, IComponent component) {
// TUP-4151
IRepositoryViewObject object = seletetedNode.getObject();
if (component == null || object == null) {
return false;
}
ComponentProperties currentComponentProperties = null;
if (object instanceof RepositoryViewObject) {
RepositoryViewObject repositoryViewObj = (RepositoryViewObject) object;
Connection connection = ((ConnectionItem) repositoryViewObj.getProperty().getItem()).getConnection();
if (canHandle(connection)) {
GenericConnection genericConnection = (GenericConnection) connection;
currentComponentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(genericConnection.getCompProperties(), connection);
}
} else if (object instanceof MetadataTableRepositoryObject) {
MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) object;
currentComponentProperties = SchemaUtils.getCurrentComponentProperties(metaTableRepObj);
} else if (object instanceof MetadataColumnRepositoryObject) {
MetadataColumnRepositoryObject metaColumnRepObj = (MetadataColumnRepositoryObject) object;
ModelElement element = metaColumnRepObj.getTdColumn();
if (element != null && element.eContainer() instanceof MetadataTable) {
MetadataTable metadataTable = (MetadataTable) element.eContainer();
IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
currentComponentProperties = SchemaUtils.getCurrentComponentProperties(newTable);
}
}
if (currentComponentProperties != null) {
try {
List<ComponentDefinition> possibleComponents = ComponentsUtils.getComponentService().getPossibleComponents(currentComponentProperties);
if (component instanceof Component) {
ComponentDefinition componentDefinition = ((Component) component).getComponentDefinition();
return possibleComponents.contains(componentDefinition);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
return false;
}
Aggregations