public List<ModuleNeeded> getModulesNeeded() {
    if (modulesNeeded.isEmpty() && component != null && component.getModulesNeeded() != null) {
      // if the list is empty, initialize from the original component
      // this avoids complex refactor to initialize this list all the time, and add the possibility
      // to add more
      // modules needed to one original component

      modulesNeeded.addAll(component.getModulesNeeded());
    }
    return modulesNeeded;
  }
Ejemplo n.º 2
0
  @Override
  public boolean valid(
      Item item,
      ERepositoryObjectType type,
      RepositoryNode seletetedNode,
      IComponent component,
      String repositoryType) {
    if (!(item instanceof MDMConnectionItem)) {
      return false;
    }
    // for mdm
    MdmConceptType mdmType = null;
    if (item instanceof MDMConnectionItem) {
      MDMConnectionItem mdmItem = (MDMConnectionItem) item;
      if (seletetedNode != null
          && seletetedNode.getObject() instanceof MetadataTableRepositoryObject) {
        MetadataTableRepositoryObject object =
            (MetadataTableRepositoryObject) seletetedNode.getObject();
        if (mdmItem.getConnection() instanceof MDMConnection) {
          MDMConnection connection = (MDMConnection) mdmItem.getConnection();
          for (Object obj : connection.getSchemas()) {
            if (obj instanceof Concept && object.getLabel().equals(((Concept) obj).getLabel())) {
              mdmType = ((Concept) obj).getConceptType();
            }
          }
        }
      }
    }

    String componentProductname = component.getRepositoryType();
    if (componentProductname != null
        && repositoryType.endsWith(componentProductname)
        && validSub(item, type, seletetedNode, component, repositoryType)) {
      if (MdmConceptType.INPUT.equals(mdmType)
          && component.getName().endsWith(RepositoryComponentManager.INPUT)) {
        return true;
      } else if (MdmConceptType.OUTPUT.equals(mdmType)
          && component.getName().endsWith(RepositoryComponentManager.OUTPUT)) {
        return true;
      } else if (MdmConceptType.RECEIVE.equals(mdmType) && component.getName().endsWith(RECEIVE)) {
        return true;
      }
    }

    return false;
  }
 protected boolean isSubValid(
     Item item,
     ERepositoryObjectType type,
     RepositoryNode seletetedNode,
     IComponent component,
     String repositoryType) {
   boolean tableWithMap = true;
   if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
     if (component.getName().toUpperCase().endsWith(MAP)) {
       tableWithMap = false;
     }
   }
   return tableWithMap;
 }
 private static boolean filterNeededComponent(
     SortedComponentSetting[] settings, IComponent component) {
   if (settings != null && settings.length > 0 && component != null) {
     Pattern p = null;
     Matcher matcher = null;
     for (SortedComponentSetting setting : settings) {
       String pattern = setting.getPattern();
       if (pattern != null && !EMPTY.equals(pattern)) {
         p = Pattern.compile(pattern);
         matcher = p.matcher(component.getName());
         if (matcher.find()) {
           return true;
         }
       }
     }
   }
   return false;
 }
  private boolean isValid(
      Item item,
      ERepositoryObjectType type,
      RepositoryNode seletetedNode,
      IComponent component,
      String repositoryType) {
    if (component == null || repositoryType == null) {
      return false;
    }

    String componentProductname = component.getRepositoryType();
    if (componentProductname != null
        && componentProductname.contains(repositoryType)
        && isSubValid(item, type, seletetedNode, component, repositoryType)) {
      return true;
    }
    return false;
  }
  /** Constructs a new FileInputNode. */
  public FileInputDelimitedNode(
      String filename,
      String rowSep,
      String fieldSep,
      int limitRows,
      int headerRows,
      int footerRows,
      String escapeChar,
      String textEnclosure,
      boolean removeEmptyRow,
      boolean spitRecord,
      String encoding,
      EShadowProcessType fileType) {
    super("tFileInputDelimited"); // $NON-NLS-1$

    boolean csvoption = false;
    String languageName = LanguageManager.getCurrentLanguage().getName();
    switch (fileType) {
      case FILE_DELIMITED:
        csvoption = false;

        if (languageName.equals("perl")) { // $NON-NLS-1$
          int max =
              getColumnCount(
                  filename,
                  rowSep,
                  fieldSep,
                  limitRows,
                  headerRows,
                  escapeChar,
                  textEnclosure,
                  EShadowProcessType.FILE_DELIMITED);
          this.setColumnNumber(max);

        } else {

          int max = 0;
          try {

            max =
                FileInputDelimited.getMaxColumnCount(
                    trimParameter(filename),
                    trimParameter(encoding),
                    trimParameter(StringUtils.loadConvert(fieldSep, languageName)),
                    trimParameter(StringUtils.loadConvert(rowSep, languageName)),
                    true,
                    spitRecord,
                    headerRows,
                    limitRows);

          } catch (IOException e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
          }
          if (max > 0) {
            this.setColumnNumber(max);
          }
        }
        break;

      case FILE_CSV:
        csvoption = true;
        if (languageName.equals("perl")) { // $NON-NLS-1$
          int max =
              getColumnCount(
                  filename,
                  rowSep,
                  fieldSep,
                  limitRows,
                  headerRows,
                  escapeChar,
                  textEnclosure,
                  EShadowProcessType.FILE_CSV);
          this.setColumnNumber(max);
        } else {
          CSVFileColumnConnter cr = null;
          try {
            cr = new CSVFileColumnConnter();
            cr.setSeperator(
                trimParameter(StringUtils.loadConvert(fieldSep, languageName)).charAt(0));
            int columnCount = 0;
            columnCount =
                cr.countMaxColumnNumber(
                    new File(TalendTextUtils.removeQuotes(filename)), limitRows);
            if (columnCount > 0) {
              this.setColumnNumber(columnCount);
            }
          } catch (UnsupportedEncodingException e) {
            ExceptionHandler.process(e);
          } catch (FileNotFoundException e) {
            ExceptionHandler.process(e);
          } catch (IOException e) {
            ExceptionHandler.process(e);
          }
        }
        break;

      default:
        break;
    }

    String[] paramNames = null;

    if (!csvoption) {
      paramNames =
          new String[] {
            "FILENAME",
            "ROWSEPARATOR",
            "FIELDSEPARATOR",
            "LIMIT",
            "HEADER",
            "FOOTER", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                      // //$NON-NLS-6$
            "ESCAPE_CHAR",
            "TEXT_ENCLOSURE",
            "REMOVE_EMPTY_ROW",
            "ENCODING",
            "CSV_OPTION",
            "SPLITRECORD"
          }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    } else {
      paramNames =
          new String[] {
            "FILENAME",
            "CSVROWSEPARATOR",
            "FIELDSEPARATOR",
            "LIMIT",
            "HEADER",
            "FOOTER", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                      // //$NON-NLS-6$
            "ESCAPE_CHAR",
            "TEXT_ENCLOSURE",
            "REMOVE_EMPTY_ROW",
            "ENCODING",
            "CSV_OPTION",
            "SPLITRECORD"
          }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    }
    String[] paramValues =
        new String[] {
          filename,
          rowSep,
          fieldSep,
          Integer.toString(limitRows),
          Integer.toString(headerRows),
          Integer.toString(footerRows),
          escapeChar,
          textEnclosure,
          Boolean.toString(removeEmptyRow),
          encoding,
          Boolean.toString(csvoption),
          Boolean.toString(spitRecord)
        };

    IComponent component =
        ComponentsFactoryProvider.getInstance()
            .get(
                "tFileInputDelimited", //$NON-NLS-1$
                ComponentCategory.CATEGORY_4_DI.getName());
    this.setElementParameters(component.createElementParameters(this));
    for (int i = 0; i < paramNames.length; i++) {
      if (paramValues[i] != null) {
        IElementParameter param = this.getElementParameter(paramNames[i]);
        if (param != null) {
          param.setValue(paramValues[i]);
        }
      }
    }
  }
    /*
     * (non-Javadoc) Method declared on IAction.
     */
    @Override
    public void run() {
      String path = null;
      if (GlobalServiceRegister.getDefault()
          .isServiceRegistered(IComponentsLocalProviderService.class)) {
        IComponentsLocalProviderService service =
            (IComponentsLocalProviderService)
                GlobalServiceRegister.getDefault()
                    .getService(IComponentsLocalProviderService.class);
        if (service != null) {
          path = service.getPreferenceStore().getString("USER_COMPONENTS_FOLDER"); // $NON-NLS-1$
        }
      }
      if (path == null || path.length() == 0) {
        new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.getString("PushToPaletteActionProvider.Error"),
                null, //$NON-NLS-1$
                Messages.getString("PushToPaletteActionProvider.ErrorMSG"),
                MessageDialog.ERROR,
                new String[] {Messages.getString("PushToPaletteActionProvider.OK")},
                0)
            .open(); //$NON-NLS-1$ //$NON-NLS-2$
        return;
      }
      File targetFile = new File(path);
      if (!targetFile.exists()) {
        new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.getString("PushToPaletteActionProvider.Error2"),
                null, //$NON-NLS-1$
                Messages.getString("PushToPaletteActionProvider.ErrorMSG2"),
                MessageDialog.ERROR,
                new String[] {Messages.getString("PushToPaletteActionProvider.OK2")},
                0)
            .open(); //$NON-NLS-1$ //$NON-NLS-2$
        return;
      }

      // fix issue 7636: Don't need to copy if component project URL and
      // user components folder are the same.
      String projectURL =
          ComponentDesigenerPlugin.getDefault()
              .getPreferenceStore()
              .getString(PluginConstant.PROJECT_URL);
      File source = new File(projectURL);

      List<String> invalidXMLs = new ArrayList();
      for (IFolder selectedFolder : selectedFolderList) {
        List<String> result = checkComponentXMLinFolder(selectedFolder.getRawLocation().toString());
        invalidXMLs.addAll(result);
      }

      // all XML are OK
      if (invalidXMLs.size() == 0) {

        if (!targetFile.equals(source)) {
          for (IFolder selectedFolder : selectedFolderList) {
            File sourceFile = selectedFolder.getRawLocation().toFile();
            String sourceComponentFolder = sourceFile.getAbsolutePath();
            String targetComponentFolder =
                targetFile.getAbsolutePath() + File.separator + sourceFile.getName();

            FileCopy.copyComponentFolder(sourceComponentFolder, targetComponentFolder, true);
          }
        }

        // add for bug TDI-26719, clear image cash from EmfComponent
        IComponentsFactory components = ComponentsFactoryProvider.getInstance();
        List<IComponent> comList = components.getCustomComponents();
        for (IComponent com : comList) {
          if (com.getImageRegistry() != null) {
            com.getImageRegistry().clear();
          }
        }

        MessageDialog warningMessageDialog =
            new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.getString("PushToPaletteActionProvider.Information"),
                null,
                Messages.getString("PushToPaletteActionProvider.InformationMSG"),
                MessageDialog.INFORMATION, // $NON-NLS-1$ //$NON-NLS-2$
                new String[] {Messages.getString("PushToPaletteActionProvider.OK3")},
                0); //$NON-NLS-1$
        warningMessageDialog.open();

        CorePlugin.getDefault().getCodeGeneratorService().refreshTemplates();
      } else {
        StringBuffer sbuffer = new StringBuffer();
        for (String invalidXML : invalidXMLs) {
          sbuffer.append(invalidXML).append("\n"); // $NON-NLS-1$
        }

        String waringInfo =
            Messages.getString("PushToPaletteActionProvider.PushToPaletteActionProvider.failed")
                + sbuffer.toString(); // $NON-NLS-1$

        MessageDialog warningMessageDialog =
            new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.getString(
                    "PushToPaletteActionProvider.PushToPaletteActionProvider.result"),
                null,
                waringInfo, //$NON-NLS-1$
                MessageDialog.WARNING,
                new String[] {Messages.getString("PushToPaletteActionProvider.OK3")},
                0); //$NON-NLS-1$

        warningMessageDialog.open();
      }
    }