use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class ImportItemUtil method checkItem.
private boolean checkItem(ItemRecord itemRecord, boolean overwrite) {
boolean result = false;
try {
Item item = itemRecord.getItem();
if (item instanceof TDQItem) {
// hide tdq first
return false;
}
ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
if (itemType == null) {
//$NON-NLS-1$
itemRecord.addError(Messages.getString("ImportItemUtil.unsupportItem"));
// can't import this item.
return false;
}
cache.initialize(itemType);
boolean isAllowMultipleName = (itemType == ERepositoryObjectType.SQLPATTERNS || itemType == ERepositoryObjectType.METADATA_FILE_XML);
String itemPath = null;
if (item.getState() != null) {
itemPath = item.getState().getPath();
} else {
itemRecord.addError(Messages.getString("ImportItemUtil.unsupportItem"));
return false;
}
boolean nameAvailable = true;
IRepositoryViewObject itemWithSameId = null;
IRepositoryViewObject itemWithSameName = null;
// take care, in cache it's RepositoryViewObject, not RepositoryObject
for (IRepositoryViewObject current : cache.getItemsFromRepository().get(itemType)) {
final Property property = itemRecord.getProperty();
if (property != null) {
if (property.getLabel() != null && property.getLabel().equalsIgnoreCase(current.getLabel()) && property.getId() != current.getId()) {
// repository.
if (!isAllowMultipleName || current.getPath().equals(itemPath)) {
nameAvailable = false;
}
// elements
if (!nameAvailable) {
itemWithSameName = current;
}
}
if (property.getId() != null && property.getId().equalsIgnoreCase(current.getId())) {
itemWithSameId = current;
}
}
}
itemRecord.setExistingItemWithSameId(itemWithSameId);
boolean idAvailable = itemWithSameId == null;
boolean isSystem = false;
// we do not import built in routines
if (item.eClass().equals(PropertiesPackage.eINSTANCE.getRoutineItem())) {
RoutineItem routineItem = (RoutineItem) item;
if (routineItem.isBuiltIn()) {
isSystem = true;
}
}
// we do not import system sql patterns
if (item.eClass().equals(PropertiesPackage.eINSTANCE.getSQLPatternItem())) {
SQLPatternItem sqlPatternItem = (SQLPatternItem) item;
if (sqlPatternItem.isSystem()) {
isSystem = true;
}
}
if (isSystem) {
itemRecord.addError(Messages.getString("RepositoryUtil.isSystem"));
return false;
}
if (nameAvailable) {
if (idAvailable) {
if (!isSystem) {
result = true;
}
/*
* else { itemRecord.addError(Messages.getString("RepositoryUtil.isSystemRoutine")); //$NON-NLS-1$
* }
*/
} else {
// same id but different name,no need to care overwrite cause the item will be considered as a
// different one,see bug 20445
itemRecord.setState(State.ID_EXISTED);
// if (overwrite) {
// result = true;
// } else {
// see bug 0005222: [Import items] [Errors and Warnings]
// id is already in use
result = true;
// RepositoryNode nodeWithSameId = RepositoryNodeUtilities.getRepositoryNode(itemWithSameId);
// IPath path = getPath(nodeWithSameId);
// itemRecord.addError(Messages.getString(
// "RepositoryUtil.idUsed", itemWithSameId.getLabel(), path.toOSString())); //$NON-NLS-1$
// }
}
} else {
if (idAvailable) {
// same name but different id
itemRecord.setState(State.NAME_EXISTED);
if (!isSystem && overwrite) {
// if anything system, don't replace the source item if same name.
// if not from system, can overwrite.
itemRecord.setExistingItemWithSameId(itemWithSameName);
result = true;
}
// if item is locked, cannot overwrite
if (result && overwrite && itemWithSameName != null) {
ERepositoryStatus status = itemWithSameName.getRepositoryStatus();
if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
//$NON-NLS-1$
itemRecord.addError(Messages.getString("RepositoryUtil.itemLocked"));
return false;
}
}
} else {
// same name and same id
itemRecord.setState(State.NAME_AND_ID_EXISTED);
if (overwrite) {
result = true;
}
if (!isSystem && overwrite && !itemWithSameName.getProperty().getLabel().equals(itemWithSameId.getProperty().getLabel())) {
// if anything system, don't replace the source item if same name.
// if not from system, can overwrite.
itemRecord.setExistingItemWithSameId(itemWithSameName);
result = true;
}
}
if (!result && !isSystem) {
//$NON-NLS-1$
itemRecord.addError(Messages.getString("RepositoryUtil.nameUsed"));
}
}
if (result && overwrite && itemRecord.getState() == State.NAME_AND_ID_EXISTED) {
// if item is locked, cannot overwrite
if (checkIfLocked(itemRecord)) {
//$NON-NLS-1$
itemRecord.addError(Messages.getString("RepositoryUtil.itemLocked"));
result = false;
}
}
} catch (Exception e) {
log.error("Error when checking item :" + itemRecord.getPath(), e);
}
return result;
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class MavenVersionManagementProjectSettingPage method updateItemsVersion.
protected void updateItemsVersion() {
List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
boolean hasJobOpenedInEditor = false;
StringBuilder builder = new StringBuilder();
for (ItemVersionObject object : checkedObjects) {
if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
hasJobOpenedInEditor = true;
JobsOpenedInEditor.add(object);
//$NON-NLS-1$
builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
} else {
closedJobs.add(object);
}
}
if (builder.length() > 0) {
builder.delete(builder.length() - 2, builder.length());
}
if (hasJobOpenedInEditor) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workBench != null) {
IWorkbenchPage page = workBench.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
if (service != null) {
for (IEditorReference editorRef : editorRefs) {
IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IMultiPageTalendEditor) {
IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
String version = null;
for (ItemVersionObject object : JobsOpenedInEditor) {
if (object.getItem().getProperty().getId().equals(process.getId())) {
version = object.getNewVersion();
break;
}
}
if (version != null) {
String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
if (version.equals(jobDefaultVersion)) {
// if default, set null to remove key from property.
version = null;
}
Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
if (process instanceof IGEFProcess) {
service.executeCommand((IGEFProcess) process, command);
}
}
}
}
}
}
}
}
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
RepositoryWorkUnit<Object>(//$NON-NLS-1$
project, //$NON-NLS-1$
"Update items Maven version") {
@Override
protected void run() throws LoginException, PersistenceException {
//$NON-NLS-1$
monitor.beginTask("Update items Maven version", closedJobs.size());
for (ItemVersionObject object : closedJobs) {
final Item item = object.getItem();
Property itemProperty = item.getProperty();
MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
monitor.subTask(itemProperty.getLabel());
FACTORY.save(project, itemProperty);
monitor.worked(1);
}
try {
FACTORY.saveProject(project);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
};
rwu.setAvoidUnloadResources(true);
rwu.executeRun();
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
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, monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException | InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class AbstractVersionManagementProjectSettingPage method processItems.
protected void processItems(List<ItemVersionObject> objects, RepositoryNode node) {
if (node == null) {
return;
}
// if the root node of type is not init, force init.
IProjectRepositoryNode root = node.getRoot();
if (root instanceof ProjectRepositoryNode) {
((ProjectRepositoryNode) root).initNode(node);
}
if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
if (node.getObject() != null) {
Property property = node.getObject().getProperty();
Item item = property.getItem();
if (item != null && filterRepositoryNode(node)) {
// must be item
ItemVersionObject object = createItemVersionObject(node, property);
objects.add(object);
}
}
} else {
IContentProvider contentProvider = treeViewer.getContentProvider();
if (contentProvider instanceof NavigatorContentServiceContentProvider) {
NavigatorContentServiceContentProvider navigatorProvider = (NavigatorContentServiceContentProvider) contentProvider;
Object[] children = navigatorProvider.getChildren(node);
for (Object child : children) {
if (child instanceof RepositoryNode) {
processItems(objects, (RepositoryNode) child);
}
}
} else {
for (IRepositoryNode child : node.getChildren()) {
processItems(objects, (RepositoryNode) child);
}
}
}
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createSQLPattern.
private void createSQLPattern(List<Object> sourceList) {
if (sourceList.size() == 0) {
return;
}
NodeContainerPart nodePart = (NodeContainerPart) getTargetEditPart();
Object model = nodePart.getModel();
if (model instanceof NodeContainer) {
Node node = ((NodeContainer) model).getNode();
IElementParameter sqlPatternValue = node.getElementParameter(EParameterName.SQLPATTERN_VALUE.getName());
if (sqlPatternValue != null) {
boolean created = false;
for (Object source : sourceList) {
if (source instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) source;
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof SQLPatternItem) {
SQLPatternItem pattern = (SQLPatternItem) item;
Property property = pattern.getProperty();
String propertyId = property.getId();
String propertyLabel = property.getLabel();
List<Map> values = (List<Map>) sqlPatternValue.getValue();
Map<String, String> patternMap = new HashMap<String, String>();
boolean contains = false;
for (Map map : values) {
String compoundId = (String) map.get(SQLPatternUtils.SQLPATTERNLIST);
String id = compoundId.split(SQLPatternUtils.ID_SEPARATOR)[0];
String name = compoundId.split(SQLPatternUtils.ID_SEPARATOR)[1];
if (id.equals(propertyId) && name.equals(propertyLabel)) {
contains = true;
break;
}
}
if (!contains) {
patternMap.put(SQLPatternUtils.SQLPATTERNLIST, propertyId + SQLPatternUtils.ID_SEPARATOR + propertyLabel);
values.add(patternMap);
sqlPatternValue.setValue(values);
created = true;
}
}
}
}
if (created) {
RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurComponentSettingsView();
}
}
}
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class WSDL2JAVAController method createRoutine.
/**
* DOC xtan Comment method "createRoutine".
*
* @param path
*/
private RoutineItem createRoutine(final IPath path, String label, File initFile, String name) {
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("");
property.setLabel(label);
final RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
routineItem.setProperty(property);
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
InputStream stream = null;
try {
stream = initFile.toURL().openStream();
byte[] innerContent = new byte[stream.available()];
stream.read(innerContent);
byteArray.setInnerContent(innerContent);
} catch (IOException e) {
ExceptionHandler.process(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
//
}
}
}
String routineContent = new String(byteArray.getInnerContent());
routineContent = chanageRoutinesPackage(routineContent, name);
byteArray.setInnerContent(routineContent.getBytes());
routineItem.setContent(byteArray);
final IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
try {
property.setId(repositoryFactory.getNextId());
repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), path);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
repositoryFactory.create(routineItem, path);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
});
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (routineItem.eResource() != null) {
addWsdlNeedLib(routineItem);
}
return routineItem;
}
Aggregations