use of org.talend.designer.core.model.utils.emf.talendfile.ParametersType in project tdi-studio-se by Talend.
the class ResetVMArgumentMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
ProcessType processType = getProcessType(item);
if (processType == null) {
return ExecutionResult.NOTHING_TO_DO;
}
ParametersType parameters = processType.getParameters();
if (parameters == null) {
return ExecutionResult.NOTHING_TO_DO;
}
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
EList listParamType = parameters.getElementParameter();
for (int j = 0; j < listParamType.size(); j++) {
ElementParameterType pType = (ElementParameterType) listParamType.get(j);
if (pType.getName().equals("JOB_RUN_VM_ARGUMENTS")) {
//$NON-NLS-1$
String value = pType.getValue().trim();
if (value != null && value.length() > 0 && !isJson(value)) {
try {
JSONObject root = new JSONObject();
JSONArray args = new JSONArray();
//$NON-NLS-1$
String[] vms = value.split(" ");
for (String vm : vms) {
args.put(vm);
}
//$NON-NLS-1$
root.put("JOB_RUN_VM_ARGUMENTS", args);
pType.setValue(root.toString());
factory.save(item, true);
break;
} catch (JSONException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ParametersType in project tdi-studio-se by Talend.
the class AbstractJobSettingsPage method isStatUseProjectSetting.
protected boolean isStatUseProjectSetting(IRepositoryViewObject object) {
Property property = object.getProperty();
ProcessItem pItem = (ProcessItem) property.getItem();
ParametersType pType = pItem.getProcess().getParameters();
String statB = ElementParameter2ParameterType.getParameterValue(pType, getParameterName().getName());
return Boolean.parseBoolean(statB);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ParametersType in project tdi-studio-se by Talend.
the class ChangeModelForRoutineParameterMigrationTask method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
if (!(item instanceof ProcessItem)) {
return ExecutionResult.NOTHING_TO_DO;
}
try {
ProcessItem item2 = (ProcessItem) item;
List<ItemInforType> oldRoutinesDependencies = (List<ItemInforType>) item2.getProcess().getRoutinesDependencies();
if (item2.getProcess().getParameters() == null || item2.getProcess().getParameters().getRoutinesParameter() == null) {
ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
item2.getProcess().setParameters(parameterType);
}
List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) item2.getProcess().getParameters().getRoutinesParameter();
List<IRepositoryViewObject> viewObjects = RoutinesUtil.getCurrentSystemRoutines();
boolean modified = false;
for (ItemInforType added : oldRoutinesDependencies) {
if (added.isSystem()) {
for (int i = 0; i < viewObjects.size(); i++) {
IRepositoryViewObject viewObject = viewObjects.get(i);
if (viewObject.getLabel().equals(added.getIdOrName())) {
RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
routinesParameterType.setId(viewObject.getId());
routinesParameterType.setName(added.getIdOrName());
routinesDependencies.add(routinesParameterType);
modified = true;
}
}
} else {
IRepositoryViewObject userRoutines = RoutinesUtil.getUserRoutines(added.getIdOrName());
if (userRoutines != null) {
RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
routinesParameterType.setId(added.getIdOrName());
routinesParameterType.setName(userRoutines.getLabel());
routinesDependencies.add(routinesParameterType);
modified = true;
}
}
}
if (modified) {
oldRoutinesDependencies.clear();
CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(item, true);
RelationshipItemBuilder.getInstance().addOrUpdateItem(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ParametersType in project tdi-studio-se by Talend.
the class ChangeModelForRoutineParameterMigrationTask2 method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
try {
List<String> possibleRoutines = new ArrayList<String>();
List<String> routinesToAdd = new ArrayList<String>();
String additionalString = LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "." : "";
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
List<IRepositoryViewObject> routines = factory.getAll(ProjectManager.getInstance().getCurrentProject(), ERepositoryObjectType.ROUTINES);
// always add the system, others must be checked
for (IRepositoryViewObject object : routines) {
if (((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
routinesToAdd.add(object.getLabel());
} else {
possibleRoutines.add(object.getLabel());
}
}
for (Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
List<IRepositoryViewObject> refRoutines = factory.getAll(project, ERepositoryObjectType.ROUTINES);
for (IRepositoryViewObject object : refRoutines) {
if (!((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
if (!possibleRoutines.contains(object.getLabel())) {
possibleRoutines.add(object.getLabel());
routines.add(object);
}
}
}
}
List<RoutinesParameterType> oldList = Collections.EMPTY_LIST;
ProcessType processType = getProcessType(item);
if (null != processType) {
if (processType.getParameters() != null && processType.getParameters().getRoutinesParameter() == null) {
ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
processType.setParameters(parameterType);
if (item instanceof ProcessItem) {
routinesToAdd.addAll(possibleRoutines);
possibleRoutines.clear();
}
} else {
if (processType.getParameters() == null) {
processType.setParameters(TalendFileFactory.eINSTANCE.createParametersType());
}
oldList = new ArrayList<RoutinesParameterType>(processType.getParameters().getRoutinesParameter());
if (oldList.isEmpty() && item instanceof ProcessItem) {
routinesToAdd.addAll(possibleRoutines);
possibleRoutines.clear();
}
processType.getParameters().getRoutinesParameter().clear();
}
if (processType.getRoutinesDependencies() != null && !processType.getRoutinesDependencies().isEmpty()) {
processType.getRoutinesDependencies().clear();
}
List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) processType.getParameters().getRoutinesParameter();
if (!possibleRoutines.isEmpty()) {
// check possible routines to setup in process
for (ElementParameterType param : (List<ElementParameterType>) processType.getParameters().getElementParameter()) {
for (String routine : possibleRoutines) {
if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
// check possible routines to setup in nodes
for (NodeType node : ((List<NodeType>) processType.getNode())) {
for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
for (String routine : possibleRoutines) {
if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
}
// check possible routines to setup in connections
for (ConnectionType connection : ((List<ConnectionType>) processType.getConnection())) {
for (ElementParameterType param : (List<ElementParameterType>) connection.getElementParameter()) {
for (String routine : possibleRoutines) {
if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
}
}
// just in case some routine dependencies exist before but are lost... (migration from 4.1.1 or 4.1.2)
for (RoutinesParameterType routine : oldList) {
if (!routinesToAdd.contains(routine.getName())) {
routinesDependencies.add(routine);
}
}
for (IRepositoryViewObject object : routines) {
if (routinesToAdd.contains(object.getLabel())) {
RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
routinesParameterType.setId(object.getId());
routinesParameterType.setName(object.getLabel());
routinesDependencies.add(routinesParameterType);
}
}
factory.save(item, true);
}
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ParametersType in project tdi-studio-se by Talend.
the class ChangePostgresDbVersionForProjectSetting method execute.
/*
* (non-Javadoc)
*
* @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
*/
@Override
public ExecutionResult execute(Project project) {
org.talend.core.model.properties.Project emfProject = project.getEmfProject();
StatAndLogsSettings statAndLogs = emfProject.getStatAndLogsSettings();
boolean modified = false;
if (statAndLogs != null && statAndLogs.getParameters() != null) {
ParametersType parameters = statAndLogs.getParameters();
List elementParameter = parameters.getElementParameter();
for (int i = 0; i < elementParameter.size(); i++) {
final Object object = elementParameter.get(i);
if (object instanceof ElementParameterTypeImpl) {
ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
String name = parameterType.getName();
if ("ON_DATABASE_FLAG".equals(name) && !Boolean.valueOf(parameterType.getValue())) {
//$NON-NLS-1$
break;
}
if ("DB_TYPE".equals(name) && parameterType.getValue().startsWith("tPostgresql")) {
//$NON-NLS-1$
modified = updateJarValue(elementParameter) || modified;
}
}
}
}
ImplicitContextSettings implicitContext = emfProject.getImplicitContextSettings();
if (implicitContext != null && implicitContext.getParameters() != null) {
ParametersType parameters = implicitContext.getParameters();
List elementParameter = parameters.getElementParameter();
for (int i = 0; i < elementParameter.size(); i++) {
final Object object = elementParameter.get(i);
if (object instanceof ElementParameterTypeImpl) {
ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
String name = parameterType.getName();
if ("FROM_DATABASE_FLAG_IMPLICIT_CONTEXT".equals(name) && !Boolean.valueOf(parameterType.getValue())) {
//$NON-NLS-1$
break;
}
if ("DB_TYPE_IMPLICIT_CONTEXT".equals(name) && parameterType.getValue().startsWith("tPostgresql")) {
//$NON-NLS-1$
modified = updateJarValueForImplici(elementParameter) || modified;
}
}
}
}
if (modified) {
try {
IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
prf.saveProject(project);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
Aggregations