示例#1
0
  @Override
  public void logOnProject(Project project) throws LoginException, PersistenceException {
    setLoggedOnProject(false);

    // TODO: review the prefs
    // new StatusPreferenceInitializer().initializeDefaultPreferences();
    IStatusPreferenceInitService statusPreferenceInitService =
        CoreRuntimePlugin.getInstance().getStatusPreferenceInitService();
    if (statusPreferenceInitService != null) {
      statusPreferenceInitService.initStatusPreference();
    }
    String productVersion = VersionUtils.getVersion();
    IBrandingService brandingService = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IBrandingService.class)) {
      brandingService =
          (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    }
    if (brandingService != null) {
      String version = brandingService.getFullProductName() + "-" + productVersion; // $NON-NLS-1$
      if (!version.equals(project.getEmfProject().getProductVersion())) {
        project.getEmfProject().setProductVersion(version);
        project.getEmfProject().getFolders().clear();
      }
    }
    // saveProject();

    setLoggedOnProject(true);
  }
示例#2
0
 protected Object getFullFolder(Project project, ERepositoryObjectType itemType, String path)
     throws PersistenceException {
   Object folder = getFolder(project, itemType);
   if (folder == null) {
     return null;
   }
   Object fullFolder;
   if (folder instanceof IFolder) {
     fullFolder = getFolder(project, itemType);
     if (path != null && !"".equals(path)) { // $NON-NLS-1$
       fullFolder = ((IFolder) fullFolder).getFolder(new Path(path));
     }
   } else {
     // FolderItem
     if (path != null && !"".equals(path)) { // $NON-NLS-1$
       // MOD mzhao feature 9207
       if (folder == null) {
         fullFolder = ResourceUtils.getProject(project).getFolder(new Path(path));
       } else {
         fullFolder =
             this.getFolderHelper(project.getEmfProject())
                 .getFolder(
                     ((FolderItem) folder).getProperty().getLabel() + "/" + path); // $NON-NLS-1$
       }
     } else {
       fullFolder = folder;
     }
   }
   return fullFolder;
 }
示例#3
0
 @Override
 public FolderItem getFolderItem(Project project, ERepositoryObjectType itemType, IPath path) {
   if (project == null) {
     // add this to fix NPE of junit for logon
     return null;
   }
   FolderHelper folderHelper = getFolderHelper(project.getEmfProject());
   String pathStr = ERepositoryObjectType.getFolderName(itemType) + IPath.SEPARATOR + path;
   FolderItem folderItem = folderHelper.getFolder(pathStr);
   if (folderItem == null && itemType != null) {
     folderItem = folderHelper.createFolder(pathStr);
   }
   return folderItem;
 }
示例#4
0
  private void getAllVersions(
      Project project, Property property, List<IRepositoryViewObject> allVersion)
      throws PersistenceException {
    ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(property.getItem());
    Object fullFolder = getFullFolder(project, itemType, property.getItem().getState().getPath());
    if (fullFolder != null) {
      allVersion.addAll(
          getSerializableFromFolder(
              project, fullFolder, property.getId(), itemType, true, false, false, true));
      if (allVersion.size() == 0) {
        // if no item found in current directory, look for all directory
        allVersion.addAll(getAllVersion(project, property.getId(), false));
      }
    } else {
      allVersion.addAll(getAllVersion(project, property.getId(), false));
    }
    if (allVersion.size() == 0 && project.getEmfProject().getReferencedProjects().size() > 0) {
      String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);

      for (ProjectReference refProject :
          (List<ProjectReference>) project.getEmfProject().getReferencedProjects()) {
        if (refProject.getBranch() != null && !parentBranch.equals(refProject.getBranch())) {
          continue;
        }
        org.talend.core.model.properties.Project emfProject = refProject.getReferencedProject();
        getAllVersions(new Project(emfProject), property, allVersion);
        if (allVersion.size() > 0) {
          break;
        }
      }
    }
    // MOD mzhao Temporary return original object. In this case, the object hasn't been updated from
    // svn server.
    if (allVersion.size() == 0) {
      allVersion.add(new RepositoryViewObject(property));
    }
  }
示例#5
0
  @Override
  public boolean isNameAvailable(
      Project project, Item item, String name, List<IRepositoryViewObject>... givenList)
      throws PersistenceException {
    if (name == null) {
      name = item.getProperty().getLabel();
    }

    if (item instanceof FolderItem) {
      FolderHelper folderHelper = getFolderHelper(project.getEmfProject());
      return !folderHelper.pathExists((FolderItem) item, name);
    }

    ERepositoryObjectType type = ERepositoryObjectType.getItemType(item);

    if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
      return false;
    }
    boolean isAllowMultipleName =
        (type == ERepositoryObjectType.SQLPATTERNS
            || type == ERepositoryObjectType.METADATA_FILE_XML);
    String path = "";
    if (item.getState() != null) {
      path = item.getState().getPath();
    }

    List<IRepositoryViewObject> list;

    if (givenList.length == 0) {
      list = getAll(project, type, true, false);
    } else {
      list = givenList[0];
    }

    for (IRepositoryViewObject current : list) {
      if (name.equalsIgnoreCase(current.getProperty().getLabel())
          && item.getProperty().getId() != current.getProperty().getId()) {
        // To check SQLPattern in same path. see bug 0005038: unable to add a SQLPattern into
        // repository.
        if (!isAllowMultipleName
            || current.getProperty().getItem().getState().getPath().equals(path)) {
          return false;
        }
      }
    }
    return true;
  }
  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());
  }
  public void updateProjectSettings()
      throws ParserConfigurationException, SAXException, IOException {
    if (this.path == null) {
      return;
    }

    File file = new File(path);
    org.talend.core.model.properties.Project project = pro.getEmfProject();

    final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
    DocumentBuilder analyseur = fabrique.newDocumentBuilder();
    analyseur.setErrorHandler(
        new ErrorHandler() {

          public void error(final SAXParseException exception) throws SAXException {
            throw exception;
          }

          public void fatalError(final SAXParseException exception) throws SAXException {
            throw exception;
          }

          public void warning(final SAXParseException exception) throws SAXException {
            throw exception;
          }
        });

    final Document document = analyseur.parse(file);
    final NodeList nodes = document.getElementsByTagName("exportParameter"); // $NON-NLS-1$
    List addedComponentSetting = new ArrayList();
    List technical = project.getTechnicalStatus();
    List documentation = project.getDocumentationStatus();
    technical.clear();
    documentation.clear();

    for (int i = 0; i < nodes.getLength(); i++) {
      final Node node = nodes.item(i);
      final NamedNodeMap attrMap = node.getAttributes();
      final Node typeAttr = attrMap.getNamedItem("type"); // $NON-NLS-1$

      if ("technicalStatus".equals(typeAttr.getTextContent())) { // $NON-NLS-1$
        updateStatus(node, attrMap, technical, "technicalStatus"); // $NON-NLS-1$
      } else if ("documentationStatus".equals(typeAttr.getTextContent())) { // $NON-NLS-1$
        updateStatus(node, attrMap, documentation, "documentationStatus"); // $NON-NLS-1$
      } else if ("security".equals(typeAttr.getTextContent())) { // $NON-NLS-1$
        project.isHidePassword();
        project.setHidePassword(Boolean.valueOf(node.getTextContent()));
      } else if ("statAndLogs".equals(typeAttr.getTextContent())) { // $NON-NLS-1$
        if (project.getStatAndLogsSettings() == null) {
          TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
          StatAndLogsSettings stats = PropertiesFactory.eINSTANCE.createStatAndLogsSettings();
          project.setStatAndLogsSettings(stats);
          stats.setParameters(talendF.createParametersType());
        }

        List statAndLogs = project.getStatAndLogsSettings().getParameters().getElementParameter();
        updateParameters(node, attrMap, statAndLogs);

      } else if ("implicitContext".equals(typeAttr.getTextContent())) { // $NON-NLS-1$
        if (project.getImplicitContextSettings() == null) {
          TalendFileFactory talendF = TalendFileFactory.eINSTANCE;

          ImplicitContextSettings implicit =
              PropertiesFactory.eINSTANCE.createImplicitContextSettings();
          project.setImplicitContextSettings(implicit);
          implicit.setParameters(talendF.createParametersType());
        }

        List implicitContexts =
            project.getImplicitContextSettings().getParameters().getElementParameter();
        updateParameters(node, attrMap, implicitContexts);

      } else if ("palette".equals(typeAttr.getTextContent())) { // $NON-NLS-1$
        List componentSettings = project.getComponentsSettings();
        boolean existed = false;
        String name = attrMap.getNamedItem("name").getTextContent(); // $NON-NLS-1$
        final Node familyAttr = attrMap.getNamedItem("family"); // $NON-NLS-1$
        Boolean hide = Boolean.valueOf(node.getTextContent());

        for (Object obj : componentSettings) {
          ComponentSetting setting = (ComponentSetting) obj;

          if (setting.getName().equals(name)) {
            if (familyAttr != null && familyAttr.getTextContent().equals(setting.getFamily())) {
              existed = true;
              setting.setHidden(hide);
            }
          }
        }
        if (!existed && familyAttr != null) {
          ComponentSetting setting = PropertiesFactory.eINSTANCE.createComponentSetting();
          setting.setFamily(familyAttr.getTextContent());
          setting.setName(name);
          setting.setHidden(hide);
          addedComponentSetting.add(setting);
        }
      }
    }

    project.getComponentsSettings().addAll(addedComponentSetting);
  }
示例#8
0
  protected void createSystemSQLPatterns() throws PersistenceException {
    ERepositoryObjectType sqlpatternsType = ERepositoryObjectType.SQLPATTERNS;
    if (sqlpatternsType == null) {
      return; // don't load, nothing to do
    }
    ILibrariesService service = null;
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
      return;
    }
    service =
        (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
    Project project = getRepositoryContext().getProject();
    FolderHelper folderHelper = getFolderHelper(project.getEmfProject());
    // will automatically set the children folders
    // FolderItem folderItem = folderHelper.getFolder("sqlPatterns/system");
    // if (folderItem == null) {
    //            folderItem = folderHelper.createFolder("sqlPatterns/system"); //$NON-NLS-1$
    // }

    List<URL> routines = service.getSystemSQLPatterns();

    List<IRepositoryViewObject> repositoryObjects = getAll(project, sqlpatternsType, false, false);

    for (URL url : routines) {
      String[] fragments = url.toString().split("/"); // $NON-NLS-1$
      String label = fragments[fragments.length - 1];
      String[] tmp = label.split("\\."); // $NON-NLS-1$

      Path relativePath = new Path(url.getFile());

      // for instance: categoryName is Teradata; fileName is
      // Loadfile.sqlpattern
      String fileName = relativePath.segment(relativePath.segmentCount() - 1);
      String categoryName = relativePath.segment(relativePath.segmentCount() - 2);

      tmp = fileName.split("\\."); // $NON-NLS-1$

      String sqlPatternLabel = tmp[0];

      SQLPatternItem existingItem = null;
      for (IRepositoryViewObject object : repositoryObjects) {
        if (object.getLabel().equals(sqlPatternLabel)
            && object.getProperty().getItem() instanceof SQLPatternItem
            && ((SQLPatternItem) object.getProperty().getItem())
                .getEltName()
                .equals(categoryName)) {
          existingItem = (SQLPatternItem) object.getProperty().getItem();
          break;
        }
      }
      // check the folder for categoryName,system,UserDefined
      // set the item's relative path in the repository view
      IPath categoryPath = new Path(categoryName);
      IPath systemPath = categoryPath.append(RepositoryConstants.SYSTEM_DIRECTORY);
      IPath userPath = categoryPath.append(RepositoryConstants.USER_DEFINED);

      IPath parentPath = new Path(ERepositoryObjectType.getFolderName(sqlpatternsType));
      if (folderHelper.getFolder(parentPath.append(categoryPath)) == null) {
        createFolder(
            getRepositoryContext().getProject(),
            sqlpatternsType,
            new Path(""),
            categoryPath //$NON-NLS-1$
                .lastSegment());
      }
      FolderItem systemFolder = folderHelper.getFolder(parentPath.append(systemPath));
      if (systemFolder == null) {
        Folder folder =
            createFolder(
                getRepositoryContext().getProject(),
                sqlpatternsType,
                categoryPath,
                systemPath.lastSegment());
        ((FolderItem) folder.getProperty().getItem()).setType(FolderType.FOLDER_LITERAL);
      }
      if (folderHelper.getFolder(parentPath.append(userPath)) == null) {
        Folder folder =
            createFolder(
                getRepositoryContext().getProject(),
                sqlpatternsType,
                categoryPath,
                userPath.lastSegment());
        ((FolderItem) folder.getProperty().getItem()).setType(FolderType.FOLDER_LITERAL);
      }
      //
      if (existingItem == null) {
        createSQLPattern(url, sqlPatternLabel, categoryName);
      } else {
        updateSQLPattern(url, existingItem);
        existingItem.setParent(systemFolder);
      }
    }
  }
示例#9
0
  protected void createSystemRoutines() throws PersistenceException {
    ERepositoryObjectType routinesType = ERepositoryObjectType.ROUTINES;
    if (routinesType == null) {
      return; // don't load, nothing to do
    }
    ILibrariesService service = null;
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
      return;
    }

    service =
        (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);

    Project project = getRepositoryContext().getProject();
    FolderHelper folderHelper = getFolderHelper(project.getEmfProject());

    List<URL> routines = service.getSystemRoutines();
    Path path = new Path(RepositoryConstants.SYSTEM_DIRECTORY);
    // will automatically set the children folders
    IPath systemRoutinePath = new Path(ERepositoryObjectType.getFolderName(routinesType));
    systemRoutinePath = systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY);
    FolderItem folderItem = folderHelper.getFolder(systemRoutinePath);
    if (folderItem == null) {
      folderItem = folderHelper.createFolder(systemRoutinePath.toString());
    }
    IPath systemRoutineApiPath = new Path(ERepositoryObjectType.getFolderName(routinesType));
    systemRoutineApiPath =
        systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY).append("api");
    FolderItem folderItemApi = folderHelper.getFolder(systemRoutineApiPath);
    if (folderItemApi == null) {
      folderItemApi = folderHelper.createFolder(systemRoutineApiPath.toString());
    }

    List<IRepositoryViewObject> repositoryObjects = getAll(project, routinesType, false, false);
    Map<String, List<LibraryInfo>> routineAndJars = coreSerivce.getRoutineAndJars();
    for (URL url : routines) {
      String[] fragments = url.toString().split("/"); // $NON-NLS-1$
      String label = fragments[fragments.length - 1];
      String[] tmp = label.split("\\."); // $NON-NLS-1$
      String routineLabel = tmp[0];

      if (routineLabel.equals(coreSerivce.getTemplateString())) {
        continue;
      }

      RoutineItem existingItem = null;
      for (IRepositoryViewObject object : repositoryObjects) {
        if (object.getLabel().equals(routineLabel)
            && object.getProperty().getItem() instanceof RoutineItem) {
          existingItem = (RoutineItem) object.getProperty().getItem();
          break;
        }
      }
      if (existingItem == null) {
        createRoutine(
            url,
            path,
            routineLabel,
            routineAndJars != null ? routineAndJars.get(routineLabel) : null);
      } else {
        updateRoutine(url, existingItem);
        existingItem.setParent(folderItem);
      }
    }
  }