private void initProperty() {
    JobInfo jobInfo =
        new JobInfo(
            processItem,
            processItem.getProcess().getDefaultContext(),
            processItem.getProperty().getVersion());
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    setProperty(PROJECT_ID, String.valueOf(currentProject.getEmfProject().getId()));
    setProperty(PROJECT_NAME, currentProject.getTechnicalLabel());

    String branchKey =
        IProxyRepositoryFactory.BRANCH_SELECTION
            + UNDER_LINE_CHAR
            + currentProject.getTechnicalLabel();
    Context ctx = CoreRuntimePlugin.getInstance().getContext();
    RepositoryContext rc = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    if (rc.getFields().containsKey(branchKey) && rc.getFields().get(branchKey) != null) {
      String branchSelection = rc.getFields().get(branchKey);
      setProperty(BRANCH, branchSelection);
    }

    setProperty(JOB_ID, jobInfo.getJobId());
    setProperty(JOB_NAME, jobInfo.getJobName());
    String jobType = processItem.getProcess().getJobType();
    if (jobType == null) {
      /*
       * should call ConvertJobsUtil.getJobTypeFromFramework(processItem)
       *
       * ConvertJobsUtil.JobType.STANDARD.getDisplayName
       */
      jobType = "Standard"; // $NON-NLS-1$
    }
    setProperty(JOB_TYPE, jobType);
    setProperty(JOB_VERSION, jobInfo.getJobVersion());
    setProperty(CONTEXT_NAME, this.contextName);
    setProperty(DATE, DATAFORMAT.format(new Date()));

    setProperty(APPLY_CONTEXY_CHILDREN, String.valueOf(applyContextToChild));
    if (CommonsPlugin.isHeadless()) {
      setProperty(ADD_STATIC_CODE, String.valueOf(addStat));
    } else {
      setProperty(ADD_STATIC_CODE, Boolean.TRUE.toString()); // TDI-23641, in studio, false always.
    }
    setProperty(COMMANDLINE_VERSION, VersionUtils.getVersion());
  }
Ejemplo n.º 2
0
  @Override
  public List<ModuleNeeded> getModulesNeededForJobs() throws PersistenceException {
    List<ModuleNeeded> importNeedsList = new ArrayList<ModuleNeeded>();
    IProxyRepositoryFactory repositoryFactory =
        CoreRuntimePlugin.getInstance().getRepositoryService().getProxyRepositoryFactory();
    ERepositoryObjectType jobType = ERepositoryObjectType.PROCESS;
    if (jobType != null) {
      List<IRepositoryViewObject> jobs = repositoryFactory.getAll(jobType, true);
      for (IRepositoryViewObject cur : jobs) {
        if (!cur.isDeleted()) {
          ProcessItem item = (ProcessItem) cur.getProperty().getItem();
          if (item == null || item.getProcess() == null) {
            continue;
          }
          List<NodeType> nodes = item.getProcess().getNode();
          for (NodeType node : nodes) {
            List<ElementParameterType> elementParameter = node.getElementParameter();
            for (ElementParameterType elementParam : elementParameter) {
              if (elementParam.getField() != null
                  && elementParam.getField().equals(EParameterFieldType.MODULE_LIST.getName())) {
                String uniquename = coreSerivce.getParameterUNIQUENAME(node);
                ModuleNeeded toAdd =
                    new ModuleNeeded(
                        Messages.getString("AbstractEMFRepositoryFactory.job")
                            + item.getProperty().getLabel(), // $NON-NLS-1$
                        elementParam.getValue(),
                        Messages.getString("AbstractEMFRepositoryFactory.requiredComponent")
                            + uniquename
                            + ".",
                        true); //$NON-NLS-1$ //$NON-NLS-2$
                importNeedsList.add(toAdd);
              }
            }
          }
        }
      }
    }

    return importNeedsList;
  }
  /**
   * DOC zli Comment method "loadProjectsettingsParameters".
   *
   * @param parameters
   */
  public static void loadProjectsettingsParameters(ParametersType parameters) {
    IEditorReference[] reference =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    designerCoreService.switchToCurJobSettingsView();
    List<IProcess2> openedProcess = designerCoreService.getOpenedProcess(reference);

    for (IProcess2 process : openedProcess) {
      if (process instanceof Element) {
        Element processElem = (Element) process;
        ElementParameter2ParameterType.loadElementParameters(processElem, parameters, null);
      }
      process.setNeedRegenerateCode(true);
    }
    IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
    IProcess process = null;

    try {
      List<IRepositoryViewObject> all = repositoryFactory.getAll(ERepositoryObjectType.PROCESS);
      for (IRepositoryViewObject object : all) {
        if (!openedProcess.contains(object)) {
          Item item = object.getProperty().getItem();
          if (item instanceof ProcessItem) {
            process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
            if (process != null && process instanceof IProcess2) {
              IProcess2 process2 = (IProcess2) process;
              if (process2 instanceof Element) {
                Element processElem = (Element) process2;
                ElementParameter2ParameterType.loadElementParameters(processElem, parameters, null);
                ProcessType processType = process2.saveXmlFile();
                if (processType != null) {
                  ((ProcessItem) item).setProcess(processType);
                }
                repositoryFactory.save(item);
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @SuppressWarnings("unchecked")
  private static String getDisplayValue(final IElementParameter param) {
    Object value = param.getValue();

    if (value instanceof String) {

      if (param.getName().equals("PROCESS_TYPE_VERSION")
          && value.equals(RelationshipItemBuilder.LATEST_VERSION)) { // $NON-NLS-1$
        String jobId =
            (String)
                param
                    .getParentParameter()
                    .getChildParameters()
                    .get("PROCESS_TYPE_PROCESS")
                    .getValue(); //$NON-NLS-1$
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId);
        if (processItem == null) {
          return ""; //$NON-NLS-1$
        }
        return processItem.getProperty().getVersion();
      }
      if (param.getName().equals("PROCESS_TYPE_CONTEXT")) { // $NON-NLS-1$
        String jobId =
            (String)
                param
                    .getParentParameter()
                    .getChildParameters()
                    .get("PROCESS_TYPE_PROCESS")
                    .getValue(); //$NON-NLS-1$
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId);
        if (processItem == null) {
          return ""; //$NON-NLS-1$
        }
        // check if the selected context exists, if not, use the default context of the job.
        boolean contextExists = false;
        for (Object object : processItem.getProcess().getContext()) {
          if (object instanceof ContextType) {
            if (((ContextType) object).getName() != null
                && ((ContextType) object).getName().equals(value)) {
              contextExists = true;
              continue;
            }
          }
        }
        if (!contextExists) {
          return processItem.getProcess().getDefaultContext();
        }
        return (String) value;
      }
      // hywang add for 6484
      if ("SELECTED_FILE".equals(param.getRepositoryValue())) { // $NON-NLS-N$ //$NON-NLS-1$
        IElementParameter propertyParam =
            param
                .getElement()
                .getElementParameter(
                    "PROPERTY:REPOSITORY_PROPERTY_TYPE"); // $NON-NLS-N$ //$NON-NLS-1$
        if (propertyParam != null
            && propertyParam.getValue() != null
            && !propertyParam.getValue().equals("")) { // $NON-NLS-1$
          try {
            IRepositoryViewObject object =
                CoreRuntimePlugin.getInstance()
                    .getProxyRepositoryFactory()
                    .getLastVersion((String) propertyParam.getValue());
            if (object != null) {
              Item item = object.getProperty().getItem();
              String extension = null;

              String rule = ""; // $NON-NLS-1$
              String processLabelAndVersion = null;
              if (item instanceof RulesItem) {
                RulesItem rulesItem = (RulesItem) item;
                extension = rulesItem.getExtension();
                if (param.getElement() instanceof INode) {
                  INode node = (INode) param.getElement();
                  IProcess process = node.getProcess();
                  String jobLabel = process.getName();
                  String jobVersion = process.getVersion();
                  processLabelAndVersion =
                      JavaResourcesHelper.getJobFolderName(jobLabel, jobVersion);
                }

                rule =
                    "rules/final/"
                        + processLabelAndVersion
                        + "/"
                        + rulesItem.getProperty().getLabel() // $NON-NLS-1$ //$NON-NLS-2$
                        + rulesItem.getProperty().getVersion()
                        + extension;
              }
              return TalendQuoteUtils.addQuotes(rule);
            } else {
              return param.getValue().toString();
            }
          } catch (Exception e) {
            ExceptionHandler.process(e);
          }
        }
      }

      return (String) value;
    }
    if (param.getFieldType() == EParameterFieldType.RADIO
        || param.getFieldType() == EParameterFieldType.CHECK
        || param.getFieldType() == EParameterFieldType.AS400_CHECK) {
      if (value instanceof Boolean) {
        return ((Boolean) param.getValue()).toString();
      } else {
        return Boolean.FALSE.toString();
      }
    }

    if (param.getFieldType() == EParameterFieldType.TABLE) {
      List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
      String[] items = param.getListItemsDisplayCodeName();
      String stringValues = "{"; // $NON-NLS-1$
      for (int i = 0; i < tableValues.size(); i++) {
        Map<String, Object> lineValues = tableValues.get(i);
        stringValues += "["; // $NON-NLS-1$
        for (int j = 0; j < items.length; j++) {

          Object currentValue = lineValues.get(items[j]);
          if (currentValue instanceof Integer) {
            IElementParameter tmpParam = (IElementParameter) param.getListItemsValue()[j];
            if (tmpParam.getListItemsDisplayName().length != 0) {
              stringValues += tmpParam.getListItemsDisplayName()[(Integer) currentValue];
            }
          } else {
            stringValues += currentValue;
          }

          if (j != (items.length - 1)) {
            stringValues += ","; // $NON-NLS-1$
          }
        }
        stringValues += "]"; // $NON-NLS-1$
        if (i != (tableValues.size() - 1)) {
          stringValues += ","; // $NON-NLS-1$
        }
      }
      stringValues += "}"; // $NON-NLS-1$
      return stringValues;
    }

    return new String(""); // $NON-NLS-1$
  }