use of org.talend.core.model.properties.SQLPatternItem 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.SQLPatternItem in project tdi-studio-se by Talend.
the class SqlTemplateImportHandler method isValidSystemItem.
@Override
public boolean isValidSystemItem(ImportItem importItem) {
boolean valid = super.valid(importItem);
if (!valid) {
return false;
}
Item item = importItem.getItem();
if (item instanceof SQLPatternItem) {
if (isSystemItem(item)) {
return true;
}
}
return false;
}
use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.
the class SaveAsSQLPatternAction method run.
@Override
public void run() {
SaveAsSQLPatternWizard processWizard = new SaveAsSQLPatternWizard(editorPart);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
if (dlg.open() == Window.OK) {
try {
SQLPatternItem sqlpatternItem = processWizard.getSQLPatternItem();
// get the IFile
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
// only for talend java version
ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
IFile file = sqlPatternSynchronizer.getSQLPatternFile(sqlpatternItem);
if (file == null) {
return;
}
// Set readonly to false since created job will always be editable.
RepositoryEditorInput repositoryEditorInput = new RepositoryEditorInput(file, sqlpatternItem);
IWorkbenchPage page = getActivePage();
IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(repositoryEditorInput.getItem().getProperty().getId(), false);
repositoryEditorInput.setRepositoryNode(repositoryNode);
// here really do the normal save as function
IDocumentProvider provider = ((StandAloneTalendJavaEditor) this.editorPart).getDocumentProvider();
provider.aboutToChange(repositoryEditorInput);
provider.saveDocument(null, repositoryEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
provider.changed(repositoryEditorInput);
// copy back from the *.java file to *.item file.
// @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
ByteArray byteArray = sqlpatternItem.getContent();
byteArray.setInnerContentFromFile(repositoryEditorInput.getFile());
IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
repFactory.save(sqlpatternItem);
// close the old editor
page.closeEditor(this.editorPart, false);
// open the new editor, because at the same time, there will update the jobSetting/componentSetting view
page.openEditor(repositoryEditorInput, StandAloneTalendJavaEditor.ID, true);
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
}
}
use of org.talend.core.model.properties.SQLPatternItem 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.SQLPatternItem in project tdi-studio-se by Talend.
the class ComponentChooseDialog method containsSQLPatternSource.
private boolean containsSQLPatternSource(List<Object> source) {
if (source.size() == 0) {
return false;
}
for (Object object : source) {
if (object instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) object;
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof SQLPatternItem) {
return true;
}
}
}
return false;
}
Aggregations