use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.
the class OpenExistVersionProcessWizard method getEditorInput.
protected RepositoryEditorInput getEditorInput(final Item item, final boolean readonly, final IWorkbenchPage page) throws SystemException {
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
return new ProcessEditorInput(processItem, true, false, readonly);
} else if (item instanceof BusinessProcessItem) {
BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
IFile file = CorePlugin.getDefault().getDiagramModelService().getDiagramFileAndUpdateResource(page, businessProcessItem);
return new RepositoryEditorInput(file, businessProcessItem);
} else if (item instanceof RoutineItem) {
final RoutineItem routineItem = (RoutineItem) item;
final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
ITalendSynchronizer routineSynchronizer = codeGenService.createRoutineSynchronizer();
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
String lastVersion = factory.getLastVersion(routineItem.getProperty().getId()).getVersion();
String curVersion = routineItem.getProperty().getVersion();
routineSynchronizer.syncRoutine(routineItem, true, true);
final IFile file;
if (curVersion != null && curVersion.equals(lastVersion)) {
file = routineSynchronizer.getFile(routineItem);
} else {
file = routineSynchronizer.getRoutinesFile(routineItem);
}
if (file != null) {
return new RoutineEditorInput(file, routineItem);
}
} else if (item instanceof SQLPatternItem) {
SQLPatternItem patternItem = (SQLPatternItem) item;
final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
ISQLPatternSynchronizer SQLPatternSynchronizer = codeGenService.getSQLPatternSynchronizer();
SQLPatternSynchronizer.syncSQLPattern(patternItem, true);
IFile file = SQLPatternSynchronizer.getSQLPatternFile(patternItem);
if (file != null) {
return new RepositoryEditorInput(file, patternItem);
}
}
return null;
}
use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.
the class SaveAsSQLPatternWizard method performFinish.
public boolean performFinish() {
boolean ok = false;
try {
isUpdate = isUpdate();
if (isUpdate) {
assginVlaues(oldProperty, property);
repositoryFactory.save(oldSqlpatternItem);
// assign value
sqlpatternItem = oldSqlpatternItem;
} else {
property.setId(repositoryFactory.getNextId());
// copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
SQLPatternItem oldItem = (SQLPatternItem) repositoryEditorInput.getItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(oldItem.getContent().getInnerContent());
sqlpatternItem.setContent(byteArray);
// don't need to add depended routines.
repositoryFactory.create(sqlpatternItem, mainPage.getDestinationPath());
}
ok = true;
} catch (Exception e) {
MessageDialog.openError(getShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
return ok;
}
use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.
the class TosTokenCollector method collectProjectDetails.
private JSONObject collectProjectDetails() throws PersistenceException, JSONException {
JSONObject jObject = new JSONObject();
Project currentProject = ProjectManager.getInstance().getCurrentProject();
final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
JSONObject repoStats = new JSONObject();
// metadata
for (DynaEnum type : ERepositoryObjectType.values()) {
if (type instanceof ERepositoryObjectType && ((ERepositoryObjectType) type).isResourceItem()) {
try {
List<IRepositoryViewObject> all = factory.getAll(currentProject, (ERepositoryObjectType) type);
int nb = all.size();
if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_PATTERN_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_RULES.equals(type) || "TDQ_SOURCE_FILE_ELEMENT".equals(type.getType())) {
//$NON-NLS-1$
continue;
}
if (ERepositoryObjectType.ROUTINES.equals(type)) {
nb = 0;
List<IRepositoryViewObject> newList = new ArrayList<IRepositoryViewObject>();
for (IRepositoryViewObject object : all) {
RoutineItem rItem = (RoutineItem) object.getProperty().getItem();
if (!rItem.isBuiltIn()) {
nb++;
newList.add(object);
}
}
all = newList;
}
if (ERepositoryObjectType.SQLPATTERNS.equals(type)) {
nb = 0;
for (IRepositoryViewObject object : all) {
SQLPatternItem spItem = (SQLPatternItem) object.getProperty().getItem();
if (!spItem.isSystem()) {
nb++;
}
}
}
if ("MDM.DataModel".equals(type.getType())) {
//$NON-NLS-1$
nb = 0;
for (IRepositoryViewObject object : all) {
String path = object.getProperty().getItem().getState().getPath();
if (!"System".equals(path)) {
//$NON-NLS-1$
nb++;
}
}
}
if (nb > 0) {
JSONObject typeStats = new JSONObject();
//$NON-NLS-1$
typeStats.put("nb", nb);
if (ERepositoryObjectType.getAllTypesOfProcess().contains(type)) {
JSONObject jobDetails = new JSONObject();
collectJobDetails(all, jobDetails);
//$NON-NLS-1$
typeStats.put("details", jobDetails);
}
if (ERepositoryObjectType.ROUTINES.equals(type) || //$NON-NLS-1$
((ERepositoryObjectType) type).getFolder().startsWith("metadata/") || ERepositoryObjectType.CONTEXT.equals(type) || type.equals(ERepositoryObjectType.JOBLET)) {
int nbUsed = 0;
for (IRepositoryViewObject object : all) {
List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getId());
relations.addAll(RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getLabel()));
if (relations.size() > 0) {
nbUsed++;
}
}
//$NON-NLS-1$
typeStats.put("nb.used", nbUsed);
}
if (ERepositoryObjectType.METADATA_CONNECTIONS.equals(type)) {
JSONObject objects = new JSONObject();
for (IRepositoryViewObject object : all) {
DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
String dbType = ((DatabaseConnection) item.getConnection()).getDatabaseType();
int nbDbTypes = 1;
if (objects.has(dbType)) {
nbDbTypes = objects.getInt(dbType);
nbDbTypes++;
}
objects.put(dbType, nbDbTypes);
}
//$NON-NLS-1$
typeStats.put("types", objects);
}
repoStats.put(type.getType(), typeStats);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
//$NON-NLS-1$
jObject.put(PROJECTS.getKey(), repoStats);
jObject.put(TYPE.getKey(), ProjectManager.getInstance().getProjectType(currentProject));
int nbRef = ProjectManager.getInstance().getAllReferencedProjects().size();
if (nbRef > 0) {
jObject.put("nb.refProjects", nbRef);
}
return jObject;
}
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;
}
Aggregations