예제 #1
0
 protected Item copyFromResource(Resource createResource, String newItemLabel)
     throws PersistenceException, BusinessException {
   if (newItemLabel != null) {
     Item newItem =
         (Item)
             EcoreUtil.getObjectByType(
                 createResource.getContents(), PropertiesPackage.eINSTANCE.getItem());
     Property property = newItem.getProperty();
     property.setId(getNextId());
     property.setAuthor(getRepositoryContext().getUser());
     property.setLabel(newItemLabel);
     property.setDisplayName(newItemLabel);
     // BUG TDI-25050:If here throw exception,it will block the copy action
     // if (!isNameAvailable(getRepositoryContext().getProject(), property.getItem(), null)) {
     // throw new
     // BusinessException(Messages.getString("AbstractEMFRepositoryFactory.cannotGenerateItem"));
     // //$NON-NLS-1$
     // }
     EcoreUtil.resolveAll(createResource);
     return newItem;
   } else {
     boolean changeLabelWithCopyPrefix = true;
     return copyFromResource(createResource, changeLabelWithCopyPrefix);
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.talend.core.ui.ILastVersionChecker#isLastVersion(org.talend.core.model.properties.Item)
  */
 public boolean isLastVersion(Item item) {
   if (item.getProperty() != null) {
     if (item.getProperty().getId() == null) {
       return true;
     }
     try {
       List<IRepositoryViewObject> allVersion =
           ProxyRepositoryFactory.getInstance().getAllVersion(item.getProperty().getId());
       if (allVersion != null && !allVersion.isEmpty()) {
         String lastVersion = VersionUtils.DEFAULT_VERSION;
         for (IRepositoryViewObject object : allVersion) {
           if (VersionUtils.compareTo(object.getVersion(), lastVersion) > 0) {
             lastVersion = object.getVersion();
           }
         }
         if (VersionUtils.compareTo(item.getProperty().getVersion(), lastVersion) == 0) {
           return true;
         }
       }
     } catch (PersistenceException e) {
       ExceptionHandler.process(e);
     }
   }
   return false;
 }
  /**
   * DOC smallet Comment method "openRoutineEditor".
   *
   * @param item
   * @throws SystemException
   * @throws PartInitException
   */
  public IEditorPart openSQLPatternEditor(SQLPatternItem item, boolean readOnly)
      throws SystemException, PartInitException {
    if (item == null) {
      return null;
    }
    ICodeGeneratorService service =
        (ICodeGeneratorService)
            GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);

    ECodeLanguage lang =
        ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY))
            .getProject()
            .getLanguage();
    ISQLPatternSynchronizer routineSynchronizer = service.getSQLPatternSynchronizer();

    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();

    IEditorReference[] editorParts = page.getEditorReferences();
    String talendEditorID =
        "org.talend.designer.core.ui.editor.StandAloneTalend"
            + lang.getCaseName()
            + "Editor"; //$NON-NLS-1$ //$NON-NLS-2$
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
      IEditorPart editor = reference.getEditor(false);
      if (talendEditorID.equals(editor.getSite().getId())) {
        // TextEditor talendEditor = (TextEditor) editor;
        RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
        Item item2 = editorInput.getItem();
        if (item2 != null
            && item2 instanceof SQLPatternItem
            && item2.getProperty().getId().equals(item.getProperty().getId())) {
          if (item2.getProperty().getVersion().equals(item.getProperty().getVersion())) {
            page.bringToTop(editor);
            found = true;
            talendEditor = editor;
            break;
          } else {
            page.closeEditor(editor, false);
          }
        }
      }
    }

    if (!found) {
      routineSynchronizer.syncSQLPattern(item, true);
      IFile file = routineSynchronizer.getSQLPatternFile(item);

      RepositoryEditorInput input = new RepositoryEditorInput(file, item);
      input.setReadOnly(readOnly);
      talendEditor = page.openEditor(input, talendEditorID); // $NON-NLS-1$
    }

    return talendEditor;
  }
예제 #4
0
 @Override
 public LockInfo getLockInfo(Item item) {
   if (item.getState().isLocked()) {
     return new LockInfo(
         item.getState().getLocker().getLogin(),
         "studio",
         item.getState().getLockDate()); // $NON-NLS-1$
   }
   return new LockInfo("", "", null);
 }
예제 #5
0
  /**
   * Test method for {@link
   * org.talend.dataprofiler.core.CorePlugin#itemIsOpening(org.talend.core.model.properties.Item,
   * boolean)}.
   */
  @Test
  public void testItemIsOpeningItemBoolean() {
    try {
      CorePlugin cpMock = mock(CorePlugin.class);
      PowerMockito.mockStatic(CorePlugin.class);
      when(CorePlugin.getDefault()).thenReturn(cpMock);

      IWorkbench workbenchMock = mock(IWorkbench.class);
      when(cpMock.getWorkbench()).thenReturn(workbenchMock);

      IWorkbenchWindow workbenchWindowMock = mock(IWorkbenchWindow.class);
      when(workbenchMock.getActiveWorkbenchWindow()).thenReturn(workbenchWindowMock);

      IWorkbenchPage workbenchPageMock = mock(IWorkbenchPage.class);
      when(workbenchWindowMock.getActivePage()).thenReturn(workbenchPageMock);

      IEditorReference editorRefMock = mock(IEditorReference.class);
      IEditorReference[] editorRefMocks = new IEditorReference[] {editorRefMock};
      when(workbenchPageMock.getEditorReferences()).thenReturn(editorRefMocks);

      FileEditorInput fileEditorInputMock = mock(FileEditorInput.class);
      when(editorRefMock.getEditorInput()).thenReturn(fileEditorInputMock);

      String path1 = "/abc1"; // $NON-NLS-1$
      String path2 = "/abc2"; // $NON-NLS-1$

      IFile inputFileMock = mock(IFile.class);
      when(fileEditorInputMock.getFile()).thenReturn(inputFileMock);

      IPath inputFilePathMock = mock(IPath.class);
      when(inputFileMock.getFullPath()).thenReturn(inputFilePathMock);

      when(inputFilePathMock.toString()).thenReturn(path1);

      Item itemMock = mock(Item.class);
      Property propertyMock = mock(Property.class);
      when(itemMock.getProperty()).thenReturn(propertyMock);

      Resource resourceMock = mock(Resource.class);
      when(propertyMock.eResource()).thenReturn(resourceMock);

      IPath ipathMock = mock(IPath.class);
      PowerMockito.mockStatic(PropertyHelper.class);
      when(PropertyHelper.getItemPath(propertyMock)).thenReturn(ipathMock);
      when(ipathMock.toString()).thenReturn(path2);

      CorePlugin cp = new CorePlugin();
      assertFalse(cp.itemIsOpening(itemMock, false));
    } catch (PartInitException e) {
      fail(e.getMessage());
    }
  }
 @Override
 public void execute() {
   if (findProcessProvider != null) {
     oldImage = findProcessProvider.getIcons(process);
     findProcessProvider.setIcons((IProcess) elem, newImage);
   }
   if (changeCmd != null) {
     changeCmd.execute();
   }
   // see bug 15062
   final Item item = process.getProperty().getItem();
   if (item instanceof JobletProcessItem) {
     String label = item.getProperty().getLabel();
     CoreImageProvider.removeComponentImage(label);
   } // end
 }
예제 #7
0
  protected Item copyFromResource(Resource createResource, boolean changeLabelWithCopyPrefix)
      throws PersistenceException, BusinessException {
    Item newItem =
        (Item)
            EcoreUtil.getObjectByType(
                createResource.getContents(), PropertiesPackage.eINSTANCE.getItem());
    Property property = newItem.getProperty();
    property.setId(getNextId());
    property.setAuthor(getRepositoryContext().getUser());

    if (changeLabelWithCopyPrefix) {
      setPropNewName(property);
    }
    EcoreUtil.resolveAll(createResource);
    return newItem;
  }
예제 #8
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 openedByBrowser(Item item, URL url) {
    if (url == null || item == null) {
      return;
    }

    WebBrowserEditorInput input = new WebBrowserEditorInput(url);
    // add for bug TDI-21189 at 2012-6-8,that a document exist is only opened one time in studio
    try {
      IWorkbenchPage page = getActivePage();
      IEditorReference[] iEditorReference = page.getEditorReferences();
      for (IEditorReference editors : iEditorReference) {
        if (WebBrowserEditor.WEB_BROWSER_EDITOR_ID.equals(editors.getId())) {
          IEditorPart iEditorPart = editors.getEditor(true);
          if (iEditorPart != null && iEditorPart instanceof WebBrowserEditor) {
            WebBrowserEditorInput webBrowserEditorInput =
                (WebBrowserEditorInput) iEditorPart.getEditorInput();
            if (webBrowserEditorInput != null && url.equals(webBrowserEditorInput.getURL())) {
              // page.activate(iEditorPart);
              iEditorPart.init(iEditorPart.getEditorSite(), webBrowserEditorInput);
              DocumentationUtil.setPartItemId(
                  (WebBrowserEditor) iEditorPart,
                  item.getProperty().getId(),
                  ERepositoryObjectType.getItemType(item));
              return;
            }
          }
        }
      }
      input.setName(item.getProperty().getLabel());
      input.setToolTipText(
          item.getProperty().getLabel() + " " + item.getProperty().getVersion()); // $NON-NLS-1$
      IEditorPart editorPart = page.openEditor(input, WebBrowserEditor.WEB_BROWSER_EDITOR_ID);
      if (editorPart != null && editorPart instanceof WebBrowserEditor) {
        DocumentationUtil.setPartItemId(
            (WebBrowserEditor) editorPart,
            item.getProperty().getId(),
            ERepositoryObjectType.getItemType(item));
      }
    } catch (PartInitException e) {
      MessageBoxExceptionHandler.process(e);
    }
  }
 private IFile getBeanFile(Item beanItem) throws SystemException {
   IRunProcessService service = CamelDesignerPlugin.getDefault().getRunProcessService();
   ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
   if (talendProcessJavaProject == null) {
     return null;
   }
   IFolder beanFolder =
       talendProcessJavaProject.getSrcSubFolder(null, JavaUtils.JAVA_BEANS_DIRECTORY);
   IFile file = beanFolder.getFile(beanItem.getProperty().getLabel() + JavaUtils.JAVA_EXTENSION);
   return file;
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.talend.core.repository.link.AbstractFileEditorInputLinker#getRepoNodeFromEditor(org.eclipse.ui.IEditorPart)
   */
  @Override
  protected RepositoryNode getRepoNodeFromEditor(IEditorPart editorPart) {
    if (editorPart != null
        && editorPart instanceof org.talend.repository.services.utils.LocalWSDLEditor) {

      IEditorInput editorInput =
          ((org.talend.repository.services.utils.LocalWSDLEditor) editorPart).getEditorInput();
      if (editorInput instanceof ServiceEditorInput) {
        Item item = ((ServiceEditorInput) editorInput).getItem();
        if (item != null) {
          IRepositoryNode node =
              RepositorySeekerManager.getInstance()
                  .searchRepoViewNode(item.getProperty().getId(), false);
          if (node != null && node instanceof RepositoryNode) {
            return (RepositoryNode) node;
          }
        }
      }
    }
    return null;
  }
  private boolean canDelete(IRepositoryViewObject viewObj) {
    Item item = viewObj.getProperty().getItem();
    if (!(item instanceof ContainerItem)) {
      return true;
    }

    String path = item.getState().getPath();
    List<String> paths =
        Arrays.asList(
            ITransformerV2NodeConsDef.PATH_BEFOREDEL,
            ITransformerV2NodeConsDef.PATH_BEFORESAVE,
            ITransformerV2NodeConsDef.PATH_ENTITYACTION,
            ITransformerV2NodeConsDef.PATH_WELCOMEACTION,
            ITransformerV2NodeConsDef.PATH_SMARTVIEW,
            ITransformerV2NodeConsDef.PATH_OTHER);
    if (path.startsWith("/")) { // $NON-NLS-1$
      path = path.substring(1);
    }
    boolean canDel = !paths.contains(path);

    return canDel;
  }
 /**
  * DOC msjian Comment method "extractFolder".
  *
  * @param oldItem
  * @param oldModelElement
  * @return
  */
 @Override
 protected IFolder extractFolder(Item oldItem, ModelElement oldObject) {
   boolean inCurrentMainProject = ProjectManager.getInstance().isInCurrentMainProject(oldItem);
   if (inCurrentMainProject) {
     Resource resource = oldItem.eResource();
     IPath path = new Path(resource.getURI().toPlatformString(false));
     IFile oldFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
     return (IFolder) oldFile.getParent();
   } else {
     // for the reference project node, we get its folder in current project.
     return ResourceManager.getOneFolder(EResourceConstant.JRXML_TEMPLATE);
   }
 }
  public static RepositoryComponentSetting getSetting(Item item, ERepositoryObjectType type) {
    if (item == null) {
      return null;
    }
    boolean subItem = (type == ERepositoryObjectType.METADATA_CON_TABLE);

    for (RepositoryComponentSetting setting : getSettings()) {
      Class<Item>[] classes = setting.getClasses();
      if (classes != null) {
        for (Class<Item> clazz : classes) {
          if (clazz.isAssignableFrom(item.getClass())) {
            if (clazz.isAssignableFrom(DatabaseConnectionItem.class)) { // for db
              EDatabaseTypeName[] dbTypes = setting.getDbTypes();
              if (dbTypes != null) {
                for (EDatabaseTypeName dbType : dbTypes) {
                  DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                  DatabaseConnection dbConnection = (DatabaseConnection) dbItem.getConnection();
                  // use the display name as the database type
                  if (dbType.getDisplayName().equals(dbConnection.getDatabaseType())) {
                    if (!subItem) {
                      return setting;
                    }
                    if (subItem && setting.withSchema()) {
                      return setting;
                    }
                  }
                }
              }
            } else {
              return setting;
            }
          }
        }
      }
    }
    return null;
  }
  public static List<ContextTableTabParentModel> constructContextDatas(
      List<IContextParameter> contextDatas) {
    List<ContextTableTabParentModel> output = new ArrayList<ContextTableTabParentModel>();
    if (!contextDatas.isEmpty()) {
      int i = 0;
      for (IContextParameter para : contextDatas) {
        String sourceId = para.getSource();
        if (IContextParameter.BUILT_IN.equals(sourceId)) {
          sourceId = para.getSource();
          ContextTableTabParentModel firstLevelNode = new ContextTableTabParentModel();
          String sourceLabel = sourceId;
          ContextItem contextItem = ContextUtils.getContextItemById2(sourceId);
          if (contextItem != null) {
            sourceLabel = contextItem.getProperty().getLabel();
            final ProjectManager pm = ProjectManager.getInstance();
            if (!pm.isInCurrentMainProject(contextItem)) {
              final Project project = pm.getProject(contextItem);
              if (project != null) {
                firstLevelNode.setProjectLabel(project.getLabel());
              }
            }
          }
          firstLevelNode.setOrder(i);
          firstLevelNode.setSourceName(sourceLabel);
          firstLevelNode.setSourceId(sourceId);
          firstLevelNode.setContextParameter(para);
          output.add(firstLevelNode);
        } else {
          ContextTableTabParentModel firstLevelNode = null;
          if (sourceId != null) {
            firstLevelNode = lookupContextParentForNonBuiltinNode(sourceId, output);
            if (firstLevelNode == null) {
              firstLevelNode = new ContextTableTabParentModel();
              output.add(firstLevelNode);
              String sourceLabel = sourceId;
              // the item maybe a joblet item now
              Item contextItem = ContextUtils.getRepositoryContextItemById(sourceId);
              if (contextItem != null) {
                sourceLabel = contextItem.getProperty().getLabel();
                final ProjectManager pm = ProjectManager.getInstance();
                if (!pm.isInCurrentMainProject(contextItem)) {
                  final Project project = pm.getProject(contextItem);
                  if (project != null) {
                    firstLevelNode.setProjectLabel(project.getLabel());
                  }
                }
              }
              firstLevelNode.setSourceName(sourceLabel);
              firstLevelNode.setOrder(i);
              firstLevelNode.setSourceId(sourceId);
            }

            ContextTableTabChildModel child = new ContextTableTabChildModel();
            child.setSourceId(sourceId);
            child.setContextParameter(para);
            child.setParent(firstLevelNode);
            firstLevelNode.addChild(child);
          }
        }
        i++;
      }
    }
    return output;
  }