/** * Method "setPropNewName". Try first the new name with "[PROPERTY_NAME]_Copy", then, if it * already exists, try again with "[PROPERTY_NAME]_CopyN" where N is number between 1 and * Integer.MAX. * * @param copiedProperty * @throws PersistenceException * @throws BusinessException */ private void setPropNewName(Property copiedProperty) throws PersistenceException, BusinessException { String originalLabel = copiedProperty.getDisplayName(); String copy = "_Copy"; // $NON-NLS-1$ String initialTry = originalLabel + copy; copiedProperty.setLabel(initialTry); // changed by hqzhang for TDI-19965 copiedProperty.setDisplayName(initialTry); if (isNameAvailable(getRepositoryContext().getProject(), copiedProperty.getItem(), null)) { return; } else { long index = 1; while (!isNameAvailable( getRepositoryContext().getProject(), copiedProperty.getItem(), null)) { if (index < 0) { throw new BusinessException( Messages.getString("AbstractEMFRepositoryFactory.cannotGenerateItem")); // $NON-NLS-1$ } String nextTry = originalLabel + copy + (index++); copiedProperty.setLabel(nextTry); // changed by hqzhang for TDI-19965 copiedProperty.setDisplayName(nextTry); } } }
/** * create jrxml file. * * @param path * @param label * @param initFile * @param extendtion * @return */ public TDQJrxmlItem createJrxml(IPath path, String label, File initFile, String extendtion) { Property property = PropertiesFactory.eINSTANCE.createProperty(); property.setVersion(VersionUtils.DEFAULT_VERSION); property.setStatusCode(PluginConstant.EMPTY_STRING); property.setLabel(label); TDQJrxmlItem routineItem = org.talend.dataquality.properties.PropertiesFactory.eINSTANCE.createTDQJrxmlItem(); routineItem.setProperty(property); routineItem.setExtension(extendtion); routineItem.setName(label); ByteArray byteArray = duplicateByteArray(initFile); routineItem.setContent(byteArray); IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance(); try { property.setId(repositoryFactory.getNextId()); if (path != null) { repositoryFactory.createParentFoldersRecursively( ERepositoryObjectType.getItemType(routineItem), path); } repositoryFactory.create(routineItem, path); } catch (PersistenceException e) { ExceptionHandler.process(e); } return routineItem; }
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); } }
private void getProcess() { initPerlArray(); this.component.setNumber(number); if (component.getProcess() instanceof IProcess2) { // get current job context manager. jobContextManager = component.getProcess().getContextManager(); } Property property = PropertiesFactory.eINSTANCE.createProperty(); property.setLabel(PREVIEW + "_RowGenerator2"); // $NON-NLS-1$ property.setId(PREVIEW + "_RowGenerator2"); // $NON-NLS-1$ proc = new RowGenProcess(property, component); }
/** * DOC smallet Comment method "createRoutine". * * @param url * @throws PersistenceException */ private void createRoutine(URL url, IPath path, String label, List<LibraryInfo> neededJars) throws PersistenceException { if (url == null) { throw new IllegalArgumentException(); } InputStream stream = null; try { Property property = PropertiesFactory.eINSTANCE.createProperty(); property.setId(getNextId()); property.setLabel(label); ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray(); stream = url.openStream(); byte[] innerContent = new byte[stream.available()]; stream.read(innerContent); stream.close(); byteArray.setInnerContent(innerContent); // String basePath = System.getProperty("user.dir") + File.separator + "plugins"; RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem(); routineItem.setProperty(property); routineItem.setContent(byteArray); routineItem.setBuiltIn(true); if (neededJars != null) { for (LibraryInfo jar : neededJars) { IMPORTType type = ComponentFactory.eINSTANCE.createIMPORTType(); type.setMESSAGE(""); type.setNAME(label); type.setREQUIRED(true); type.setMODULE(jar.getLibName()); type.setBundleID(jar.getBundleId()); routineItem.getImports().add(type); } } if (!routineItem.getProperty().getLabel().equals(coreSerivce.getTemplateString())) { create(getRepositoryContext().getProject(), routineItem, path, true); } } catch (IOException ioe) { if (stream != null) { try { stream.close(); } catch (IOException e) { throw new PersistenceException(ioe); } } throw new PersistenceException(ioe); } }
private void createSQLPattern(URL url, String sqlPatternLabel, String categoryName) throws PersistenceException { if (url == null) { throw new IllegalArgumentException(); } InputStream stream = null; try { Property property = PropertiesFactory.eINSTANCE.createProperty(); property.setId(getNextId()); property.setLabel(sqlPatternLabel); ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray(); stream = url.openStream(); byte[] innerContent = new byte[stream.available()]; stream.read(innerContent); stream.close(); byteArray.setInnerContent(innerContent); SQLPatternItem sqlpatternItem = PropertiesFactory.eINSTANCE.createSQLPatternItem(); sqlpatternItem.setProperty(property); sqlpatternItem.setEltName(categoryName); sqlpatternItem.setContent(byteArray); sqlpatternItem.setSystem(true); // set the item's relative path in the repository view IPath categoryPath = new Path(categoryName); IPath systemPath = categoryPath.append(RepositoryConstants.SYSTEM_DIRECTORY); create(getRepositoryContext().getProject(), sqlpatternItem, systemPath, true); } catch (IOException ioe) { if (stream != null) { try { stream.close(); } catch (IOException e) { throw new PersistenceException(ioe); } } throw new PersistenceException(ioe); } }