feat(TUP-18903): add product details (#1295) (#1318)

This commit is contained in:
GGu
2017-12-11 16:53:57 +08:00
committed by nrousseau
parent fe14d638a5
commit c18b60c8fb
40 changed files with 2082 additions and 445 deletions

View File

@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Common Runtime Plug-in
Bundle-SymbolicName: org.talend.commons.runtime
Bundle-SymbolicName: org.talend.commons.runtime;singleton:=true
Bundle-Version: 7.0.1.qualifier
Require-Bundle: org.apache.log4j;visibility:=reexport,
org.apache.commons.beanutils,
@@ -18,9 +18,11 @@ Export-Package: org.talend.commons,
org.talend.commons.i18n,
org.talend.commons.i18n.internal,
org.talend.commons.runtime.debug,
org.talend.commons.runtime.extension,
org.talend.commons.runtime.helper,
org.talend.commons.runtime.model.components,
org.talend.commons.runtime.model.emf,
org.talend.commons.runtime.model.emf.provider,
org.talend.commons.runtime.model.expressionbuilder,
org.talend.commons.runtime.model.repository,
org.talend.commons.runtime.service,

View File

@@ -7,6 +7,8 @@ bin.includes = META-INF/,\
fakejdbc_driver.jar,\
modes/,\
talend.properties,\
dist/
dist/,\
plugin.xml,\
schema/
jars.compile.order = .,\
dist/org.talend.commons.runtime.jar

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="emfResourcesProvider" name="EMF Resources Provider" schema="schema/emfResourcesProvider.exsd"/>
</plugin>

View File

@@ -0,0 +1,197 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.talend.commons.runtime" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.talend.commons.runtime" id="emfResourcesProvider" name="EMF Resources Provider"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="saveOption" minOccurs="0" maxOccurs="unbounded"/>
<element ref="loadOption" minOccurs="0" maxOccurs="unbounded"/>
<element ref="resourceHandler" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="saveOption">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="provider" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="org.talend.commons.runtime.model.emf.provider.OptionProvider:"/>
</appinfo>
</annotation>
</attribute>
<attribute name="override" type="string">
<annotation>
<documentation>
the override id
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="loadOption">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="provider" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="org.talend.commons.runtime.model.emf.provider.OptionProvider:"/>
</appinfo>
</annotation>
</attribute>
<attribute name="override" type="string">
<annotation>
<documentation>
the override id
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="resourceHandler">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
resource handler for preLoad, preSave, postLoad, postSave.
</documentation>
</annotation>
</attribute>
<attribute name="override" type="string">
<annotation>
<documentation>
the override id
</documentation>
</annotation>
</attribute>
<attribute name="handler" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="org.talend.commons.runtime.model.emf.provider.ResourceHandler:"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View File

@@ -0,0 +1,222 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.extension;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
/**
* Template implementation of a registry reader that creates objects representing registry contents. Typically, an
* extension contains one element, but this reader handles multiple elements per extension.
*
* To start reading the extensions from the registry for an extension point, call the method <code>readRegistry</code>.
*
* To read children of an IConfigurationElement, call the method <code>readElementChildren</code> from your
* implementation of the method <code>readElement</code>, as it will not be done by default.
*
*/
public abstract class ExtensionRegistryReader {
private static Logger log = Logger.getLogger(ExtensionRegistryReader.class);
protected static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
private boolean isInitialized;
private final String extensionPointId;
private final String pluginId;
private final IExtensionRegistry registry;
/**
* DOC sgandon class global comment. Detailled comment <br/>
*
* $Id: talend.epf 55206 2011-02-15 17:32:14Z mhirt $
*
*/
public abstract class RegistrySafeRunnable implements ISafeRunnable {
@Override
public void handleException(Throwable exception) {
log.error("error reading extention registry", exception); //$NON-NLS-1$
}
}
/**
* The constructor.
*/
protected ExtensionRegistryReader(String aPluginId, String anExtensionPoint) {
this.registry = Platform.getExtensionRegistry();
this.pluginId = aPluginId;
this.extensionPointId = anExtensionPoint;
}
/**
* This method extracts description as a subelement of the given element.
*
* @return description string if defined, or empty string if not.
*/
protected String getDescription(IConfigurationElement config) {
IConfigurationElement[] children = config.getChildren(TAG_DESCRIPTION);
if (children.length >= 1) {
return children[0].getValue();
}
return "";//$NON-NLS-1$
}
/**
* Logs the error in the workbench log using the provided text and the information in the configuration element.
*/
protected static void logError(IConfigurationElement element, String text) {
IExtension extension = element.getDeclaringExtension();
StringBuffer buf = new StringBuffer();
buf.append("Plugin " + extension.getNamespaceIdentifier() + ", extension " + extension.getExtensionPointUniqueIdentifier());//$NON-NLS-2$//$NON-NLS-1$
buf.append("\n" + text);//$NON-NLS-1$
logError(0, buf.toString(), null);
}
/*
* Record an error against this plugin's log.
*
* @param aCode
*
* @param aMessage
*
* @param anException
*/
public static void logError(int aCode, String aMessage, Throwable anException) {
// Bundle bundle = FrameworkUtil.getBundle(RegistryReader.class);
log.log(Level.toLevel(aCode), aMessage, anException);
}
/**
* Logs a very common registry error when a required attribute is missing.
*/
protected static void logMissingAttribute(IConfigurationElement element, String attributeName) {
logError(element, "Required attribute '" + attributeName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a very common registry error when a required child is missing.
*/
protected static void logMissingElement(IConfigurationElement element, String elementName) {
logError(element, "Required sub element '" + elementName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a registry error when the configuration element is unknown.
*/
protected static void logUnknownElement(IConfigurationElement element) {
logError(element, "Unknown extension tag found: " + element.getName());//$NON-NLS-1$
}
/**
* Apply a reproducable order to the list of extensions provided, such that the order will not change as extensions
* are added or removed.
*/
protected IExtension[] orderExtensions(IExtension[] extensions) {
// By default, the order is based on plugin id sorted
// in ascending order. The order for a plugin providing
// more than one extension for an extension point is
// dependent in the order listed in the XML file.
IExtension[] sortedExtension = new IExtension[extensions.length];
System.arraycopy(extensions, 0, sortedExtension, 0, extensions.length);
Comparator<IExtension> comparer = new Comparator<IExtension>() {
@Override
public int compare(IExtension arg0, IExtension arg1) {
String s1 = arg0.getNamespaceIdentifier();
String s2 = arg1.getNamespaceIdentifier();
return s1.compareToIgnoreCase(s2);
}
};
Collections.sort(Arrays.asList(sortedExtension), comparer);
return sortedExtension;
}
/**
* Implement this method to read element's attributes. If children should also be read, then implementor is
* responsible for calling <code>readElementChildren</code>. Implementor is also responsible for logging missing
* attributes.
*
* @return true if element was recognized, false if not.
*/
protected abstract boolean readElement(IConfigurationElement element);
/**
* Read the element's children. This is called by the subclass' readElement method when it wants to read the
* children of the element.
*/
protected void readElementChildren(IConfigurationElement element) {
readElements(element.getChildren());
}
/**
* Read each element one at a time by calling the subclass implementation of <code>readElement</code>.
*
* Logs an error if the element was not recognized.
*/
protected void readElements(IConfigurationElement[] elements) {
for (int i = 0; i < elements.length; i++) {
if (!readElement(elements[i])) {
logUnknownElement(elements[i]);
}
}
}
/**
* Read one extension by looping through its configuration elements.
*/
protected void readExtension(IExtension extension) {
readElements(extension.getConfigurationElements());
}
/**
* Start the registry reading process using the supplied plugin ID and extension point.
*/
public void readRegistry() {
if (isInitialized) {
return;
}
synchronized (this) {
if (!isInitialized) {
IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPointId);
if (point == null) {
point = registry.getExtensionPoint(extensionPointId);
if (point == null) {
return;
}
}
IExtension[] extensions = point.getExtensions();
extensions = orderExtensions(extensions);
for (IExtension extension : extensions) {
readExtension(extension);
}
isInitialized = true;
}
}
}
}

View File

@@ -16,7 +16,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -40,6 +39,7 @@ import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
/***/
public class EmfHelper {
@@ -206,8 +206,8 @@ public class EmfHelper {
if (resource.getURI() == null) {
return;
}
Map options = EmfResourcesFactoryReader.INSTANCE.getSaveOptions(resource);
HashMap options = new HashMap(2);
options.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
options.put(XMLResource.OPTION_ESCAPE_USING_CDATA, Boolean.TRUE);
try {

View File

@@ -0,0 +1,219 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.SafeRunner;
import org.talend.commons.CommonsPlugin;
import org.talend.commons.runtime.extension.ExtensionRegistryReader;
/**
* DOC ggu class global comment. Detailled comment
*/
public class EmfResourcesFactoryReader extends ExtensionRegistryReader {
public static final EmfResourcesFactoryReader INSTANCE = new EmfResourcesFactoryReader();
/*
* id==> bean
*/
private Map<String, OptionProviderBean> saveOptionsBeans = new HashMap<String, OptionProviderBean>();
private Map<String, OptionProviderBean> loadOptionsBeans = new HashMap<String, OptionProviderBean>();
private Map<String, ResourceHandlerBean> resourceHandlerBeans = new HashMap<String, ResourceHandlerBean>();
/*
* id ==> provider
*/
private Map<String, OptionProvider> saveOptionsProviders = new HashMap<String, OptionProvider>();
private Map<String, OptionProvider> loadOptionsProviders = new HashMap<String, OptionProvider>();
private Map<String, ResourceHandler> resourceHandlers = new HashMap<String, ResourceHandler>();
class ExtensionBean {
String id, description, overrideId;
}
class OptionProviderBean extends ExtensionBean {
OptionProvider provider;
}
class ResourceHandlerBean extends ExtensionBean {
ResourceHandler handler;
}
private EmfResourcesFactoryReader() {
super(CommonsPlugin.PLUGIN_ID, "emfResourcesProvider"); //$NON-NLS-1$
init();
}
void init() {
readRegistry();
cleanOverrideIdsForOption(saveOptionsProviders, saveOptionsBeans);
cleanOverrideIdsForOption(loadOptionsProviders, loadOptionsBeans);
cleanOverrideIdsForHandler(resourceHandlers, resourceHandlerBeans);
}
private void cleanOverrideIdsForOption(Map<String, OptionProvider> optionProviders,
Map<String, ? extends ExtensionBean> extensionMap) {
Map<String, ? extends ExtensionBean> withoutOverrideMap = cleanOverrideIds(extensionMap);
for (Map.Entry<String, ? extends ExtensionBean> entry : withoutOverrideMap.entrySet()) {
ExtensionBean value = entry.getValue();
if (value instanceof OptionProviderBean) {
final OptionProvider optionProvider = ((OptionProviderBean) value).provider;
optionProviders.put(entry.getKey(), optionProvider);
}
}
}
private void cleanOverrideIdsForHandler(Map<String, ResourceHandler> handlers,
Map<String, ? extends ExtensionBean> extensionMap) {
Map<String, ? extends ExtensionBean> withoutOverrideMap = cleanOverrideIds(extensionMap);
for (Map.Entry<String, ? extends ExtensionBean> entry : withoutOverrideMap.entrySet()) {
ExtensionBean value = entry.getValue();
if (value instanceof ResourceHandlerBean) {
final ResourceHandler optionProvider = ((ResourceHandlerBean) value).handler;
handlers.put(entry.getKey(), optionProvider);
}
}
}
private Map<String, ? extends ExtensionBean> cleanOverrideIds(Map<String, ? extends ExtensionBean> extensionMap) {
Set<String> ids = new HashSet<String>();
Map<String, ? extends ExtensionBean> withoutOverrideMap = new HashMap<>(extensionMap);
for (Map.Entry<String, ? extends ExtensionBean> e : withoutOverrideMap.entrySet()) {
final String overrideId = e.getValue().overrideId;
if (overrideId != null) {
ids.add(overrideId);
}
}
// remove override ids
final Iterator<String> removediterator = withoutOverrideMap.keySet().iterator();
while (removediterator.hasNext()) {
if (ids.contains(removediterator.next())) {
removediterator.remove();
}
}
return withoutOverrideMap;
}
public Map<String, Object> getSaveOptions(Object resource) {
Map<String, Object> saveOptions = new HashMap<String, Object>();
for (Map.Entry<String, OptionProvider> entry : saveOptionsProviders.entrySet()) {
final OptionProvider provider = entry.getValue();
if (provider.checkSave(resource)) {
saveOptions.put(provider.getName(), provider.getValue());
}
}
return saveOptions;
}
public Map<String, Object> getLoadOptions(Object resource) {
Map<String, Object> loadOptions = new HashMap<String, Object>();
for (Map.Entry<String, OptionProvider> entry : loadOptionsProviders.entrySet()) {
final OptionProvider provider = entry.getValue();
if (provider.checkLoad(resource)) {
loadOptions.put(provider.getName(), provider.getValue());
}
}
return loadOptions;
}
public Map<String, OptionProvider> getSaveOptionsProviders() {
return saveOptionsProviders;
}
public boolean existedSaveOption(ResourceOption option) {
return getSaveOptionsProviders().containsKey(option.getName());
}
public Map<String, OptionProvider> getLoadOptionsProviders() {
return loadOptionsProviders;
}
public ResourceHandler[] getResourceHandlers() {
return resourceHandlers.values().toArray(new ResourceHandler[resourceHandlers.size()]);
}
@Override
protected boolean readElement(final IConfigurationElement element) {
if ("saveOption".equals(element.getName())) { //$NON-NLS-1$
SafeRunner.run(new RegistrySafeRunnable() {
@Override
public void run() throws Exception {
createProvider(saveOptionsBeans, element);
}
});
}
if ("loadOption".equals(element.getName())) { //$NON-NLS-1$
SafeRunner.run(new RegistrySafeRunnable() {
@Override
public void run() throws Exception {
createProvider(loadOptionsBeans, element);
}
});
}
if ("resourceHandler".equals(element.getName())) { //$NON-NLS-1$
SafeRunner.run(new RegistrySafeRunnable() {
@Override
public void run() throws Exception {
String id = element.getAttribute("id"); //$NON-NLS-1$
String description = element.getAttribute("description"); //$NON-NLS-1$
String overrideId = element.getAttribute("override"); //$NON-NLS-1$
ResourceHandler handler = (ResourceHandler) element.createExecutableExtension("handler");//$NON-NLS-1$
ResourceHandlerBean bean = new ResourceHandlerBean();
bean.id = id;
bean.description = description;
bean.overrideId = overrideId;
bean.handler = handler;
resourceHandlerBeans.put(id, bean);
}
});
}
return false;
}
private void createProvider(Map<String, OptionProviderBean> map, IConfigurationElement element) throws CoreException {
String id = element.getAttribute("id"); //$NON-NLS-1$
String description = element.getAttribute("description"); //$NON-NLS-1$
String overrideId = element.getAttribute("override"); //$NON-NLS-1$
OptionProvider provider = (OptionProvider) element.createExecutableExtension("provider");//$NON-NLS-1$
OptionProviderBean bean = new OptionProviderBean();
bean.id = id;
bean.description = description;
bean.overrideId = overrideId;
bean.provider = provider;
map.put(id, bean);
}
}

View File

@@ -0,0 +1,32 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
/**
* DOC ggu class global comment. Detailled comment
*/
public abstract class OptionProvider {
public abstract String getName();
public abstract Object getValue();
public boolean checkSave(Object resource) {
return true; // nothing to check by default
}
public boolean checkLoad(Object resource) {
return true; // nothing to check by default
}
}

View File

@@ -0,0 +1,40 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
/**
* DOC ggu class global comment. Detailled comment
*/
public abstract class ResourceHandler {
public void preLoad(Object resource, InputStream inputStream, Map<?, ?> options) {
// nothing to do by default
}
public void postLoad(Object resource, InputStream inputStream, Map<?, ?> options) {
// nothing to do by default
}
public void preSave(Object resource, OutputStream outputStream, Map<?, ?> options) {
// nothing to do by default
}
public void postSave(Object resource, OutputStream outputStream, Map<?, ?> options) {
// nothing to do by default
}
}

View File

@@ -0,0 +1,59 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
/**
* DOC ggu class global comment. Detailled comment
*/
public enum ResourceOption {
CREATATION,
MIGRATION,
ITEM_IMPORTATION,
DEMO_IMPORTATION, ;
private final OptionProvider provider;
private ResourceOption() {
this(Boolean.TRUE);
}
private ResourceOption(final Object value) {
this.provider = new OptionProvider() {
@Override
public String getName() {
return getName0();
}
@Override
public Object getValue() {
return value;
}
};
}
public OptionProvider getProvider() {
return provider;
}
public String getName() {
return getName0();
}
private String getName0() {
return ("option_" + name()).toLowerCase();
}
}

View File

@@ -699,6 +699,21 @@
</parameterHandler>
</extension>
<extension
point="org.talend.commons.runtime.emfResourcesProvider">
<saveOption
id="save.option.resource.handler"
provider="org.talend.core.repository.model.ResourceHandlerOptionProvider">
</saveOption>
<loadOption
id="load.option.resource.handler"
provider="org.talend.core.repository.model.ResourceHandlerOptionProvider">
</loadOption>
<resourceHandler
handler="org.talend.core.repository.model.ProductValuesResourceHandler"
id="resource.handler.product.values">
</resourceHandler>
</extension>
</plugin>

View File

@@ -274,8 +274,8 @@ public abstract class AbstractEMFRepositoryFactory extends AbstractRepositoryFac
}
for (IRepositoryViewObject current : list) {
if ((name.equalsIgnoreCase(current.getProperty().getLabel()) || name.equalsIgnoreCase(current.getProperty().getDisplayName()))
&& item.getProperty().getId() != current.getProperty().getId()) {
if ((name.equalsIgnoreCase(current.getProperty().getLabel()) || name.equalsIgnoreCase(current.getProperty()
.getDisplayName())) && 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;
@@ -729,6 +729,7 @@ public abstract class AbstractEMFRepositoryFactory extends AbstractRepositoryFac
if (!version.equals(project.getEmfProject().getProductVersion())) {
project.getEmfProject().setProductVersion(version);
project.getEmfProject().getFolders().clear();
saveProject(project);
}
}
// saveProject();
@@ -896,7 +897,7 @@ public abstract class AbstractEMFRepositoryFactory extends AbstractRepositoryFac
getAllVersions(project, property, allVersion);
for (IRepositoryViewObject repositoryObject : allVersion) {
Property uptodateProperty = repositoryObject.getProperty();
if (uptodateProperty!=null&&uptodateProperty.getVersion().equals(property.getVersion())) {
if (uptodateProperty != null && uptodateProperty.getVersion().equals(property.getVersion())) {
return uptodateProperty;
}
}
@@ -1031,8 +1032,8 @@ public abstract class AbstractEMFRepositoryFactory extends AbstractRepositoryFac
@Override
public void afterLogon(IProgressMonitor monitor) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService runProcessService = (IRunProcessService) GlobalServiceRegister.getDefault()
.getService(IRunProcessService.class);
IRunProcessService runProcessService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(
IRunProcessService.class);
try {
runProcessService.getTalendProcessJavaProject().cleanMavenFiles(monitor);
TimeMeasure.step("logOnProject", "clean Maven files"); //$NON-NLS-1$ //$NON-NLS-2$

View File

@@ -0,0 +1,70 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.repository.model;
import java.io.OutputStream;
import java.util.Date;
import java.util.Map;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.talend.commons.runtime.model.emf.provider.ResourceHandler;
import org.talend.commons.runtime.model.emf.provider.ResourceOption;
import org.talend.core.model.properties.PropertiesPackage;
import org.talend.core.model.properties.Property;
import org.talend.core.runtime.repository.item.ItemProductValuesHelper;
/**
* DOC ggu class global comment. Detailled comment
*/
public class ProductValuesResourceHandler extends ResourceHandler {
@Override
public void preSave(Object resource, OutputStream outputStream, Map<?, ?> options) {
if (resource instanceof XMLResource) {
final Property prop = (Property) EcoreUtil.getObjectByType(((XMLResource) resource).getContents(),
PropertiesPackage.eINSTANCE.getProperty());
if (prop != null) {
/*
* need ignore, when:
*
* 1) import, will do create also, and created and modified keys will be set in migration task. and set
* the import date in ItemProductValuesHelper. Else, if existed already nothing to do.
*
* 2) migrate in 2 cases, when import, will do point 1. when logon, just do migration task
*/
if (!options.containsKey(ResourceOption.ITEM_IMPORTATION.getName())
&& !options.containsKey(ResourceOption.DEMO_IMPORTATION.getName())
&& !options.containsKey(ResourceOption.MIGRATION.getName())) {
Date saveDate = new Date();
if (options.containsKey(ResourceOption.CREATATION.getName())) {
ItemProductValuesHelper.setValuesWhenCreate(prop, saveDate);
}
// if no any keys, do migration too.
// currently, especially when copy/paste items, if no migration task to do
ItemProductValuesHelper.setValuesWhenMigrate(prop);
// generally, work for modification in studio
ItemProductValuesHelper.setValuesWhenModify(prop, saveDate);
}
// always remove the date when save
prop.setCreationDate(null);
prop.setModificationDate(null);
}
}
}
}

View File

@@ -121,7 +121,9 @@ import org.talend.core.repository.utils.RepositoryPathProvider;
import org.talend.core.repository.utils.XmiResourceManager;
import org.talend.core.runtime.CoreRuntimePlugin;
import org.talend.core.runtime.process.ITalendProcessJavaProject;
import org.talend.core.runtime.repository.item.ItemProductKeys;
import org.talend.core.runtime.services.IMavenUIService;
import org.talend.core.runtime.util.ItemDateParser;
import org.talend.core.runtime.util.JavaHomeUtil;
import org.talend.core.service.ICoreUIService;
import org.talend.cwm.helper.SubItemHelper;
@@ -135,7 +137,6 @@ import org.talend.repository.documentation.ERepositoryActionName;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.RepositoryConstants;
import org.talend.utils.io.FilesUtils;
import orgomg.cwm.objectmodel.core.ModelElement;
/**
@@ -781,7 +782,9 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
IRepositoryViewObject object = new RepositoryObject(objToDelete.getProperty());
boolean isExtendPoint = false;
fireRepositoryPropertyChange(ERepositoryActionName.DELETE_FOREVER.getName(), null, object);
if (isFullLogonFinished()) {
fireRepositoryPropertyChange(ERepositoryActionName.DELETE_FOREVER.getName(), null, object);
}
ERepositoryObjectType repositoryObjectType = object.getRepositoryObjectType();
ICoreService coreService = getCoreService();
@@ -816,7 +819,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
}
}
if (repositoryObjectType == ERepositoryObjectType.PROCESS) {
if (repositoryObjectType == ERepositoryObjectType.PROCESS && isFullLogonFinished()) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
if (service != null) {
@@ -1044,7 +1047,6 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
return this.repositoryFactoryFromProvider.getAllVersion(project, id, avoidSaveProject);
}
@Override
public List<IRepositoryViewObject> getAllVersion(Project project, String id, String folderPath, ERepositoryObjectType type)
throws PersistenceException {
@@ -1515,7 +1517,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
if (getStatus(obj) == ERepositoryStatus.LOCK_BY_USER || obj instanceof JobletDocumentationItem
|| obj instanceof JobDocumentationItem) {
Date commitDate = obj.getState().getCommitDate();
Date modificationDate = obj.getProperty().getModificationDate();
Date modificationDate = ItemDateParser.parseAdditionalDate(obj.getProperty(), ItemProductKeys.DATE.getModifiedKey());
if (modificationDate == null || commitDate == null || modificationDate.before(commitDate)) {
boolean unlocked = this.repositoryFactoryFromProvider.unlock(obj);
if (unlocked) {

View File

@@ -0,0 +1,92 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.repository.model;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.runtime.model.emf.provider.OptionProvider;
import org.talend.commons.runtime.model.emf.provider.ResourceHandler;
/**
* DOC ggu class global comment. Detailled comment
*/
public class ResourceHandlerOptionProvider extends OptionProvider {
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.provider.EOptionProvider#getName()
*/
@Override
public String getName() {
return XMLResource.OPTION_RESOURCE_HANDLER;
}
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.provider.EOptionProvider#getValue()
*/
@Override
public Object getValue() {
return new XMLResource.ResourceHandler() {
ResourceHandler[] handlers;
ResourceHandler[] getResourceHandlers() {
if (handlers == null) {
synchronized (ResourceHandlerOptionProvider.class) {
if (handlers == null) {
handlers = EmfResourcesFactoryReader.INSTANCE.getResourceHandlers();
}
}
}
return handlers;
}
@Override
public void preLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) {
for (ResourceHandler handler : getResourceHandlers()) {
handler.preLoad(resource, inputStream, options);
}
}
@Override
public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) {
for (ResourceHandler handler : getResourceHandlers()) {
handler.postLoad(resource, inputStream, options);
}
}
@Override
public void preSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) {
for (ResourceHandler handler : getResourceHandlers()) {
handler.preSave(resource, outputStream, options);
}
}
@Override
public void postSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) {
for (ResourceHandler handler : getResourceHandlers()) {
handler.postSave(resource, outputStream, options);
}
}
};
}
}

View File

@@ -55,7 +55,7 @@ public abstract class AbstractJobDeleteListener implements PropertyChangeListene
protected Project getProject(IRepositoryObject repositoryObject) {
String projectLabel = repositoryObject.getProjectLabel();
Project currentProject = ProjectManager.getInstance().getCurrentProject();
if (currentProject.getTechnicalLabel().equalsIgnoreCase(projectLabel)) {
if (currentProject != null && currentProject.getTechnicalLabel().equalsIgnoreCase(projectLabel)) {
return currentProject;
}
{
@@ -65,8 +65,8 @@ public abstract class AbstractJobDeleteListener implements PropertyChangeListene
*/
// Project project = ProjectManager.getInstance().getProjectFromProjectLabel(projectLabel);
}
org.talend.core.model.properties.Project emfProject = ProjectManager.getInstance()
.getProject(repositoryObject.getProperty());
org.talend.core.model.properties.Project emfProject = ProjectManager.getInstance().getProject(
repositoryObject.getProperty());
Project project = new Project(emfProject);
return project;
}

View File

@@ -47,6 +47,7 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.EmfHelper;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
import org.talend.commons.utils.workbench.resources.ResourceUtils;
import org.talend.core.GlobalServiceRegister;
@@ -148,6 +149,16 @@ public class XmiResourceManager {
}
public Property loadProperty(IResource iResource) {
final Map<Object, Object> oldLoadOptions = new HashMap<Object, Object>(resourceSet.getLoadOptions());
try {
return doLoadProperty(iResource);
} finally {
resourceSet.getLoadOptions().clear();
resourceSet.getLoadOptions().putAll(oldLoadOptions);
}
}
private Property doLoadProperty(IResource iResource) {
Property property = null;
// force unload old version, or the UI won't be synchronized all the time to the current file.
@@ -177,6 +188,8 @@ public class XmiResourceManager {
}
}
}
Map options = EmfResourcesFactoryReader.INSTANCE.getLoadOptions(propertyUri);
resourceSet.getLoadOptions().putAll(options);
Resource propertyResource = resourceSet.getResource(propertyUri, true);

View File

@@ -63,6 +63,7 @@ Export-Package: org.talend.commons.utils.generation,
org.talend.core.runtime.repository,
org.talend.core.runtime.repository.build,
org.talend.core.runtime.repository.demo,
org.talend.core.runtime.repository.item,
org.talend.core.runtime.repository.selection,
org.talend.core.runtime.schedulingrule,
org.talend.core.runtime.services,

View File

@@ -12,8 +12,6 @@
// ============================================================================
package org.talend.core.hadoop.creator;
import java.util.Date;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.utils.VersionUtils;
@@ -48,7 +46,6 @@ public abstract class AbstractHadoopConnectionCreator implements IHadoopConnecti
protected void setPropertyParameters(Property connectionProperty) {
connectionProperty.setDisplayName(relativeHadoopClusterItem.getProperty().getLabel() + "_" + getTypeName()); //$NON-NLS-1$
connectionProperty.setLabel(connectionProperty.getDisplayName());
connectionProperty.setModificationDate(new Date());
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext()
.getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);

View File

@@ -35,10 +35,18 @@ public interface IRepositoryObject extends IRepositoryViewObject {
public void setStatusCode(String statusCode);
/**
* won't set the date any more, it will be deal with when save file
*/
@Deprecated
public void setCreationDate(Date value);
public void setDescription(String value);
/**
* won't set the date any more, it will be deal with when save file
*/
@Deprecated
public void setModificationDate(Date value);
public void setPurpose(String value);

View File

@@ -37,13 +37,14 @@ import org.talend.core.model.properties.ItemState;
import org.talend.core.model.properties.PropertiesFactory;
import org.talend.core.model.properties.Property;
import org.talend.core.model.properties.User;
import org.talend.core.runtime.repository.item.ItemProductKeys;
import org.talend.core.runtime.util.ItemDateParser;
import org.talend.cwm.helper.ConnectionHelper;
import org.talend.cwm.helper.PackageHelper;
import org.talend.repository.ProjectManager;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.IProxyRepositoryService;
import org.talend.repository.model.IRepositoryNode;
import orgomg.cwm.objectmodel.core.Package;
import orgomg.cwm.resource.relational.Catalog;
@@ -116,7 +117,7 @@ public class RepositoryObject implements IRepositoryObject {
@Override
public Date getCreationDate() {
return this.property.getCreationDate();
return ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getCreatedKey());
}
@Override
@@ -131,7 +132,7 @@ public class RepositoryObject implements IRepositoryObject {
@Override
public Date getModificationDate() {
return this.property.getModificationDate();
return ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getModifiedKey());
}
@Override
@@ -165,7 +166,7 @@ public class RepositoryObject implements IRepositoryObject {
@Override
public void setCreationDate(Date value) {
this.property.setCreationDate(value);
// this.property.setCreationDate(value);
}
@Override
@@ -180,7 +181,7 @@ public class RepositoryObject implements IRepositoryObject {
@Override
public void setModificationDate(Date value) {
this.property.setModificationDate(value);
// this.property.setModificationDate(value);
}
@Override
@@ -220,12 +221,11 @@ public class RepositoryObject implements IRepositoryObject {
try {
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(getAuthor());
connectionProperty.setCreationDate(getCreationDate());
connectionProperty.getAdditionalProperties().addAll(property.getAdditionalProperties());
connectionProperty.setDescription(getDescription());
connectionProperty.setId(getId());
connectionProperty.setLabel(getLabel());
connectionProperty.setDisplayName(getDisplayName());
connectionProperty.setModificationDate(getModificationDate());
connectionProperty.setPurpose(getPurpose());
connectionProperty.setStatusCode(getStatusCode());
connectionProperty.setVersion(getVersion());

View File

@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.talend.commons.exception.PersistenceException;
@@ -52,6 +53,8 @@ import org.talend.core.model.properties.LinkDocumentationItem;
import org.talend.core.model.properties.PropertiesFactory;
import org.talend.core.model.properties.Property;
import org.talend.core.model.properties.User;
import org.talend.core.runtime.repository.item.ItemProductKeys;
import org.talend.core.runtime.util.ItemDateParser;
import org.talend.core.ui.IJobletProviderService;
import org.talend.core.ui.ISparkJobletProviderService;
import org.talend.core.ui.ISparkStreamingJobletProviderService;
@@ -62,7 +65,6 @@ import org.talend.repository.ProjectManager;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.IProxyRepositoryService;
import org.talend.repository.model.IRepositoryNode;
import orgomg.cwm.objectmodel.core.Package;
import orgomg.cwm.resource.relational.Catalog;
@@ -116,17 +118,19 @@ public class RepositoryViewObject implements IRepositoryViewObject {
private static final String DI = "DI";
private static final String TIP = "same name item with other project";
private String framework;
private boolean avoidGuiInfos;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public RepositoryViewObject(Property property, boolean avoidGuiInfos) {
this.id = property.getId();
this.author = property.getAuthor();
this.creationDate = property.getCreationDate();
this.creationDate = ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getCreatedKey());
this.description = property.getDescription();
this.modificationDate = property.getModificationDate();
this.modificationDate = ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getModifiedKey());
this.label = property.getLabel();
this.displayName = property.getDisplayName();
this.purpose = property.getPurpose();
@@ -137,9 +141,14 @@ public class RepositoryViewObject implements IRepositoryViewObject {
org.talend.core.model.properties.Project emfproject = ProjectManager.getInstance().getProject(property.getItem());
this.projectLabel = emfproject.getLabel();
this.path = property.getItem().getState().getPath();
if (property.getAdditionalProperties() != null
&& property.getAdditionalProperties().containsKey("FRAMEWORK")) { //$NON-NLS-1$
setFramework((String) property.getAdditionalProperties().get("FRAMEWORK")); //$NON-NLS-1$
EMap additionalProperties2 = property.getAdditionalProperties();
if (additionalProperties2 != null) {
for (Object key : additionalProperties2.keySet()) {
this.additionalProperties.put(key.toString(), additionalProperties2.get(key));
}
}
if (additionalProperties2 != null && additionalProperties2.containsKey("FRAMEWORK")) { //$NON-NLS-1$
setFramework((String) additionalProperties2.get("FRAMEWORK")); //$NON-NLS-1$
} else {
setFramework(null);
}
@@ -212,19 +221,19 @@ public class RepositoryViewObject implements IRepositoryViewObject {
return image;
}
public static Image getDefaultJobletImage(Item item ) {
public static Image getDefaultJobletImage(Item item) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkJobletProviderService.class)) {
ISparkJobletProviderService sparkJobletService = (ISparkJobletProviderService) GlobalServiceRegister
.getDefault().getService(ISparkJobletProviderService.class);
ISparkJobletProviderService sparkJobletService = (ISparkJobletProviderService) GlobalServiceRegister.getDefault()
.getService(ISparkJobletProviderService.class);
if (sparkJobletService != null && sparkJobletService.isSparkJobletItem(item)) {
return ImageProvider.getImage(ECoreImage.SPARK_JOBLET_COMPONENT_ICON);
return ImageProvider.getImage(ECoreImage.SPARK_JOBLET_COMPONENT_ICON);
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkStreamingJobletProviderService.class)) {
ISparkStreamingJobletProviderService sparkStreamingJobletService = (ISparkStreamingJobletProviderService) GlobalServiceRegister
.getDefault().getService(ISparkStreamingJobletProviderService.class);
if (sparkStreamingJobletService != null && sparkStreamingJobletService.isSparkStreamingJobletItem(item)) {
return ImageProvider.getImage(ECoreImage.SPARK_STREAMING_JOBLET_COMPONENT_ICON);
return ImageProvider.getImage(ECoreImage.SPARK_STREAMING_JOBLET_COMPONENT_ICON);
}
}
return ImageProvider.getImage(ECoreImage.JOBLET_COMPONENT_ICON);
@@ -304,6 +313,10 @@ public class RepositoryViewObject implements IRepositoryViewObject {
return this.version;
}
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
@Override
public Property getProperty() {
exception = null;
@@ -329,9 +342,9 @@ public class RepositoryViewObject implements IRepositoryViewObject {
modified = factory.isModified(property);
this.id = property.getId();
this.author = property.getAuthor();
this.creationDate = property.getCreationDate();
this.creationDate = ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getCreatedKey());
this.description = property.getDescription();
this.modificationDate = property.getModificationDate();
this.modificationDate = ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getModifiedKey());
this.label = property.getLabel();
this.displayName = property.getDisplayName();
this.purpose = property.getPurpose();
@@ -343,8 +356,7 @@ public class RepositoryViewObject implements IRepositoryViewObject {
repositoryStatus = factory.getStatus(property.getItem());
InformationLevel informationLevel = property.getMaxInformationLevel();
informationStatus = factory.getStatus(informationLevel);
if (property.getAdditionalProperties() != null
&& property.getAdditionalProperties().containsKey("FRAMEWORK")) { //$NON-NLS-1$
if (property.getAdditionalProperties() != null && property.getAdditionalProperties().containsKey("FRAMEWORK")) { //$NON-NLS-1$
setFramework((String) property.getAdditionalProperties().get("FRAMEWORK")); //$NON-NLS-1$
} else {
setFramework(null);
@@ -432,19 +444,23 @@ public class RepositoryViewObject implements IRepositoryViewObject {
}
@SuppressWarnings("unchecked")
public RepositoryViewObject cloneNewObject() {
RepositoryViewObject object = null;
try {
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(getAuthor());
connectionProperty.setCreationDate(getCreationDate());
// connectionProperty.setCreationDate(getCreationDate());
connectionProperty.setDescription(getDescription());
connectionProperty.setId(getId());
connectionProperty.setLabel(getLabel());
connectionProperty.setModificationDate(getModificationDate());
// connectionProperty.setModificationDate(getModificationDate());
connectionProperty.setPurpose(getPurpose());
connectionProperty.setStatusCode(getStatusCode());
connectionProperty.setVersion(getVersion());
connectionProperty.getAdditionalProperties().putAll(getProperty().getAdditionalProperties());
final Item oldItem = getProperty().getItem();
DatabaseConnectionItem newItem = null;
if (oldItem instanceof DatabaseConnectionItem) {
@@ -684,6 +700,7 @@ public class RepositoryViewObject implements IRepositoryViewObject {
/**
* Getter for framework.
*
* @return the framework
*/
public String getFramework() {
@@ -692,6 +709,7 @@ public class RepositoryViewObject implements IRepositoryViewObject {
/**
* Sets the framework.
*
* @param framework the framework to set
*/
public void setFramework(String framework) {

View File

@@ -0,0 +1,46 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.runtime.repository.item;
/**
* DOC ggu class global comment. Detailled comment
*/
public enum ItemProductKeys {
FULLNAME("product_fullname"),
DATE("date"),
VERSION("product_version"), ;
private String key;
private ItemProductKeys(String key) {
this.key = key;
}
public String getKey() {
return key;
}
public String getImportKey() {
return "import_" + getKey();
}
public String getCreatedKey() {
return "created_" + getKey();
}
public String getModifiedKey() {
return "modified_" + getKey();
}
}

View File

@@ -0,0 +1,241 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.runtime.repository.item;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.emf.common.util.EMap;
import org.talend.commons.utils.VersionUtils;
import org.talend.core.GlobalServiceRegister;
import org.talend.core.model.properties.Project;
import org.talend.core.model.properties.Property;
import org.talend.core.ui.branding.IBrandingService;
import org.talend.repository.ProjectManager;
/**
* DOC ggu class global comment. Detailled comment
*/
@SuppressWarnings({ "unchecked", "rawtypes", "nls" })
public final class ItemProductValuesHelper {
/*
* 2017-10-09T14:30:19.367+0800
*/
public static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
public static String getCurDateTime() {
return DATEFORMAT.format(new Date());
}
public static boolean existed(Property property) {
if (property == null) {
return false;
}
EMap additionalProperties = property.getAdditionalProperties();
return additionalProperties.containsKey(ItemProductKeys.FULLNAME.getModifiedKey())
|| additionalProperties.containsKey(ItemProductKeys.FULLNAME.getCreatedKey());
}
/**
*
* Set the created keys with date
*
*/
public static boolean setValuesWhenCreate(Property property, Date date) {
if (property == null) {
return false;
}
if (date == null) {
date = new Date();
}
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IBrandingService.class)) {
return false;
}
EMap additionalProperties = property.getAdditionalProperties();
IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(
IBrandingService.class);
additionalProperties.put(ItemProductKeys.FULLNAME.getCreatedKey(), brandingService.getFullProductName());
additionalProperties.put(ItemProductKeys.VERSION.getCreatedKey(), VersionUtils.getDisplayVersion());
additionalProperties.put(ItemProductKeys.DATE.getCreatedKey(), DATEFORMAT.format(date));
property.setCreationDate(null);
return true;
}
/**
*
* Set the modified keys with date when save .properties file
*/
public static boolean setValuesWhenModify(Property property, Date date) {
if (property == null) {
return false;
}
if (date == null) {
date = new Date();
}
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IBrandingService.class)) {
return false;
}
EMap additionalProperties = property.getAdditionalProperties();
IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(
IBrandingService.class);
additionalProperties.put(ItemProductKeys.FULLNAME.getModifiedKey(), brandingService.getFullProductName());
additionalProperties.put(ItemProductKeys.VERSION.getModifiedKey(), VersionUtils.getDisplayVersion());
additionalProperties.put(ItemProductKeys.DATE.getModifiedKey(), DATEFORMAT.format(date));
property.setModificationDate(null);
return true;
}
/**
*
* Try to migrate the created and modified date to keys.
*/
public static boolean setValuesWhenMigrate(Property property) {
if (property == null) {
return false;
}
Project project = ProjectManager.getInstance().getProject(property);
if (project == null) { // use current project instead
project = ProjectManager.getInstance().getCurrentProject().getEmfProject();
}
return setValuesWhenMigrate(property, project);
}
public static boolean setValuesWhenMigrate(Property property, Project project) {
if (property == null) {
return false;
}
if (existed(property)) { // if existed, nothing to do
return false;
}
if (project == null) { // use current project instead
project = ProjectManager.getInstance().getCurrentProject().getEmfProject();
}
Map<String, String> productValues = getProductValues(project);
if (productValues.isEmpty()) {
return false;
}
String fullname = productValues.keySet().iterator().next();
String version = productValues.get(fullname);
String curDateTime = getCurDateTime();
//
migrateValues(property, fullname, version, curDateTime);
return true;
}
private static void migrateValues(Property property, String fullname, String version, String datetime) {
if (existed(property)) { // if existed, nothing to do
return;
}
EMap additionalProperties = property.getAdditionalProperties();
//
Date creationDate = property.getCreationDate();
additionalProperties.put(ItemProductKeys.FULLNAME.getCreatedKey(), fullname);
additionalProperties.put(ItemProductKeys.VERSION.getCreatedKey(), version);
if (creationDate != null) {
additionalProperties.put(ItemProductKeys.DATE.getCreatedKey(), DATEFORMAT.format(creationDate));
} else {
additionalProperties.put(ItemProductKeys.DATE.getCreatedKey(), datetime);
}
property.setCreationDate(null); // move the date to additional properties
//
Date modificationDate = property.getModificationDate();
additionalProperties.put(ItemProductKeys.FULLNAME.getModifiedKey(), fullname);
additionalProperties.put(ItemProductKeys.VERSION.getModifiedKey(), version);
if (modificationDate != null) {
additionalProperties.put(ItemProductKeys.DATE.getModifiedKey(), DATEFORMAT.format(modificationDate));
} else {
additionalProperties.put(ItemProductKeys.DATE.getModifiedKey(), datetime);
}
property.setModificationDate(null); // move the date to additional properties
}
/**
* When import, try to add import keys and add migration keys if possibly.
*
*/
public static boolean setValuesWhenImport(Property property, Project project) {
if (property == null || project == null) {
return false;
}
Map<String, String> productValues = getProductValues(project);
if (productValues.isEmpty()) {
return false;
}
String fullname = productValues.keySet().iterator().next();
String version = productValues.get(fullname);
String curDateTime = getCurDateTime();
return setImportValues(property, fullname, version, curDateTime);
}
public static boolean setImportValues(Property property, String fullname, String version, String datetime) {
EMap additionalProperties = property.getAdditionalProperties();
additionalProperties.put(ItemProductKeys.FULLNAME.getImportKey(), fullname);
additionalProperties.put(ItemProductKeys.VERSION.getImportKey(), version);
additionalProperties.put(ItemProductKeys.DATE.getImportKey(), datetime);
// if need, migrate other keys first, because in migration task, only for current project
migrateValues(property, fullname, version, datetime);
return true;
}
public static Map<String, String> getProductValues(Project project) {
if (project == null) {
return Collections.emptyMap();
}
return parseProduct(project.getProductVersion());
}
static Map<String, String> parseProduct(String value) {
if (value == null || value.isEmpty()) {
return Collections.emptyMap();
}
Map<String, String> result = new HashMap<String, String>();
int sepIndex = value.indexOf('-');
if (sepIndex > 0) {
String fullname = value.substring(0, sepIndex);
String version = value.substring(sepIndex + 1);
if (version.length() > 0) {
result.put(fullname, version);
}
}
if (result.isEmpty()) { // if invalid, set the full name for whole string without version
result.put(value, null);
}
return result;
}
}

View File

@@ -0,0 +1,69 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.runtime.util;
import java.text.ParseException;
import java.util.Date;
import java.util.Map;
import org.eclipse.emf.common.util.EMap;
import org.talend.core.model.properties.Property;
import org.talend.core.runtime.repository.item.ItemProductValuesHelper;
/**
* DOC ggu class global comment. Detailled comment
*/
public class ItemDateParser {
public static Date parseAdditionalDate(Property property, String key) {
if (property == null || key == null) {
return null;
}
EMap additionalProperties = property.getAdditionalProperties();
if (!additionalProperties.containsKey(key)) {
return null;
}
Object object = additionalProperties.get(key);
if (object == null) {
return null;
}
try {
Date date = ItemProductValuesHelper.DATEFORMAT.parse(object.toString());
return date;
} catch (ParseException e) {
//
}
return null;
}
public static Date parseAdditionalDate(Map<Object, Object> additionalProperties, String key) {
if (additionalProperties == null || key == null) {
return null;
}
if (!additionalProperties.containsKey(key)) {
return null;
}
Object object = additionalProperties.get(key);
if (object == null) {
return null;
}
try {
Date date = ItemProductValuesHelper.DATEFORMAT.parse(object.toString());
return date;
} catch (ParseException e) {
//
}
return null;
}
}

View File

@@ -24,13 +24,14 @@ import org.talend.utils.json.JSONObject;
*/
public interface IRemoteService extends IService {
public JSONObject getLicenseKey(String user, String password, String url, String projectLabel)
throws PersistenceException, LoginException;
public JSONObject getLicenseKey(String user, String password, String url, String projectLabel) throws PersistenceException,
LoginException;
public NexusServerBean getUpdateRepositoryUrl(String user, String password, String url)
throws PersistenceException, LoginException;
public NexusServerBean getUpdateRepositoryUrl(String user, String password, String url) throws PersistenceException,
LoginException;
public NexusServerBean getLibNexusServer(String user, String password, String url)
throws PersistenceException, LoginException, JSONException;
public NexusServerBean getLibNexusServer(String user, String password, String url) throws PersistenceException,
LoginException, JSONException;
boolean isAuthorized(String value);
}

View File

@@ -12,18 +12,7 @@
// ============================================================================
package org.talend.core.utils;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
import org.talend.commons.runtime.extension.ExtensionRegistryReader;
/**
* Template implementation of a registry reader that creates objects representing registry contents. Typically, an
@@ -36,188 +25,10 @@ import org.eclipse.core.runtime.Platform;
*
* @since 3.2
*/
public abstract class RegistryReader {
public abstract class RegistryReader extends ExtensionRegistryReader {
private static Logger log = Logger.getLogger(RegistryReader.class);
protected static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
private boolean isInitialized;
private final String extensionPointId;
private final String pluginId;
private final IExtensionRegistry registry;
/**
* DOC sgandon class global comment. Detailled comment <br/>
*
* $Id: talend.epf 55206 2011-02-15 17:32:14Z mhirt $
*
*/
public abstract class RegistrySafeRunnable implements ISafeRunnable {
@Override
public void handleException(Throwable exception) {
log.error("error reading extention registry", exception); //$NON-NLS-1$
}
}
/**
* The constructor.
*/
protected RegistryReader(String aPluginId, String anExtensionPoint) {
this.registry = Platform.getExtensionRegistry();
this.pluginId = aPluginId;
this.extensionPointId = anExtensionPoint;
super(aPluginId, anExtensionPoint);
}
/**
* This method extracts description as a subelement of the given element.
*
* @return description string if defined, or empty string if not.
*/
protected String getDescription(IConfigurationElement config) {
IConfigurationElement[] children = config.getChildren(TAG_DESCRIPTION);
if (children.length >= 1) {
return children[0].getValue();
}
return "";//$NON-NLS-1$
}
/**
* Logs the error in the workbench log using the provided text and the information in the configuration element.
*/
protected static void logError(IConfigurationElement element, String text) {
IExtension extension = element.getDeclaringExtension();
StringBuffer buf = new StringBuffer();
buf.append("Plugin " + extension.getNamespaceIdentifier() + ", extension " + extension.getExtensionPointUniqueIdentifier());//$NON-NLS-2$//$NON-NLS-1$
buf.append("\n" + text);//$NON-NLS-1$
logError(0, buf.toString(), null);
}
/*
* Record an error against this plugin's log.
*
* @param aCode
*
* @param aMessage
*
* @param anException
*/
public static void logError(int aCode, String aMessage, Throwable anException) {
// Bundle bundle = FrameworkUtil.getBundle(RegistryReader.class);
log.log(Level.toLevel(aCode), aMessage, anException);
}
/**
* Logs a very common registry error when a required attribute is missing.
*/
protected static void logMissingAttribute(IConfigurationElement element, String attributeName) {
logError(element, "Required attribute '" + attributeName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a very common registry error when a required child is missing.
*/
protected static void logMissingElement(IConfigurationElement element, String elementName) {
logError(element, "Required sub element '" + elementName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a registry error when the configuration element is unknown.
*/
protected static void logUnknownElement(IConfigurationElement element) {
logError(element, "Unknown extension tag found: " + element.getName());//$NON-NLS-1$
}
/**
* Apply a reproducable order to the list of extensions provided, such that the order will not change as extensions
* are added or removed.
*/
protected IExtension[] orderExtensions(IExtension[] extensions) {
// By default, the order is based on plugin id sorted
// in ascending order. The order for a plugin providing
// more than one extension for an extension point is
// dependent in the order listed in the XML file.
IExtension[] sortedExtension = new IExtension[extensions.length];
System.arraycopy(extensions, 0, sortedExtension, 0, extensions.length);
Comparator<IExtension> comparer = new Comparator<IExtension>() {
@Override
public int compare(IExtension arg0, IExtension arg1) {
String s1 = arg0.getNamespaceIdentifier();
String s2 = arg1.getNamespaceIdentifier();
return s1.compareToIgnoreCase(s2);
}
};
Collections.sort(Arrays.asList(sortedExtension), comparer);
return sortedExtension;
}
/**
* Implement this method to read element's attributes. If children should also be read, then implementor is
* responsible for calling <code>readElementChildren</code>. Implementor is also responsible for logging missing
* attributes.
*
* @return true if element was recognized, false if not.
*/
protected abstract boolean readElement(IConfigurationElement element);
/**
* Read the element's children. This is called by the subclass' readElement method when it wants to read the
* children of the element.
*/
protected void readElementChildren(IConfigurationElement element) {
readElements(element.getChildren());
}
/**
* Read each element one at a time by calling the subclass implementation of <code>readElement</code>.
*
* Logs an error if the element was not recognized.
*/
protected void readElements(IConfigurationElement[] elements) {
for (int i = 0; i < elements.length; i++) {
if (!readElement(elements[i])) {
logUnknownElement(elements[i]);
}
}
}
/**
* Read one extension by looping through its configuration elements.
*/
protected void readExtension(IExtension extension) {
readElements(extension.getConfigurationElements());
}
/**
* Start the registry reading process using the supplied plugin ID and extension point.
*/
public void readRegistry() {
if (isInitialized) {
return;
}
synchronized (this) {
if (!isInitialized) {
IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPointId);
if (point == null) {
point = registry.getExtensionPoint(extensionPointId);
if (point == null) {
return;
}
}
IExtension[] extensions = point.getExtensions();
extensions = orderExtensions(extensions);
for (IExtension extension : extensions) {
readExtension(extension);
}
isInitialized = true;
}
}
}
}

View File

@@ -41,11 +41,14 @@ import org.talend.core.model.properties.Item;
import org.talend.core.model.properties.PigudfItem;
import org.talend.core.model.properties.ProcessItem;
import org.talend.core.model.properties.ProjectReference;
import org.talend.core.model.properties.Property;
import org.talend.core.model.properties.RoutineItem;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.core.model.repository.IRepositoryViewObject;
import org.talend.core.model.utils.JavaResourcesHelper;
import org.talend.core.runtime.process.ITalendProcessJavaProject;
import org.talend.core.runtime.repository.item.ItemProductKeys;
import org.talend.core.runtime.util.ItemDateParser;
import org.talend.core.ui.branding.IBrandingService;
import org.talend.designer.core.ICamelDesignerCoreService;
import org.talend.designer.runprocess.IRunProcessService;
@@ -70,7 +73,7 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService service = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(
ICamelDesignerCoreService.class);
return getAll(service.getBeansType());
return getAll(service.getBeansType());
}
return Collections.emptyList();
}
@@ -129,7 +132,7 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
final String jobName = item.getProperty().getLabel();
final String folderName = JavaResourcesHelper.getJobFolderName(jobName, item.getProperty().getVersion());
return talendProcessJavaProject.getSrcFolder().getFile(
JavaResourcesHelper.getProjectFolderName(item) + '/' + folderName + '/' + jobName + JavaUtils.JAVA_EXTENSION);
JavaResourcesHelper.getProjectFolderName(item) + '/' + folderName + '/' + jobName + JavaUtils.JAVA_EXTENSION);
}
@Override
@@ -147,9 +150,9 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
if (item instanceof RoutineItem) {
final RoutineItem routineItem = (RoutineItem) item;
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(ProjectManager.getInstance().getProject(routineItem).getTechnicalLabel());
IFolder folder = project.getFolder(ERepositoryObjectType.getFolderName(ERepositoryObjectType
.getItemType(routineItem)));
.getProject(ProjectManager.getInstance().getProject(routineItem).getTechnicalLabel());
IFolder folder = project
.getFolder(ERepositoryObjectType.getFolderName(ERepositoryObjectType.getItemType(routineItem)));
IPath ipath = RepositoryNodeUtilities.getPath(routineItem.getProperty().getId());
if (ipath == null)
return null;
@@ -158,7 +161,7 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
folder = folder.getFolder(folderPath);
}
final String fileName = routineItem.getProperty().getLabel() + '_' + routineItem.getProperty().getVersion()
+ JavaUtils.ITEM_EXTENSION;
+ JavaUtils.ITEM_EXTENSION;
return folder.getFile(fileName);
}
return null;
@@ -201,45 +204,49 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
if (file == null) {
return;
}
if(routineItem.eResource() == null){
if (routineItem.eResource() == null) {
return;
}
if (routineItem.getProperty().getModificationDate() != null) {
long modificationItemDate = routineItem.getProperty().getModificationDate().getTime();
Property property = routineItem.getProperty();
Date modifiedDate = ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getModifiedKey());
if (modifiedDate != null) {
long modificationItemDate = modifiedDate.getTime();
long modificationFileDate = file.getModificationStamp();
if (modificationItemDate <= modificationFileDate) {
return;
}
} else {
routineItem.getProperty().setModificationDate(new Date());
}
if (copyToTemp) {
String uri = routineItem.eResource().getURI().trimFileExtension().appendFileExtension(FileExtensions.ITEM_EXTENSION).toPlatformString(false);
String uri = routineItem.eResource().getURI().trimFileExtension()
.appendFileExtension(FileExtensions.ITEM_EXTENSION).toPlatformString(false);
File itemFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(uri).toFile();
byte[] buf = routineItem.getContent().getInnerContent();
String charset = null;
if(itemFile.exists()){
if (itemFile.exists()) {
charset = CharsetToolkit.getCharset(itemFile);
}else{
} else {
charset = System.getProperty("file.encoding");
}
String routineContent = new String(buf, charset);
// see 14713
if (routineContent.contains("%GENERATED_LICENSE%")) { //$NON-NLS-1$
IBrandingService service = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
IBrandingService service = (IBrandingService) GlobalServiceRegister.getDefault().getService(
IBrandingService.class);
String routineHeader = service.getRoutineLicenseHeader(VersionUtils.getVersion());
routineContent = routineContent.replace("%GENERATED_LICENSE%", routineHeader); //$NON-NLS-1$
}// end
String label = routineItem.getProperty().getLabel();
String label = property.getLabel();
if (!label.equals(ITalendSynchronizer.TEMPLATE) && routineContent != null) {
routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
// routineContent = renameRoutinePackage(routineItem,
// routineContent);
if (!file.exists()) {
file.create(new ByteArrayInputStream(routineContent.getBytes(System.getProperty("file.encoding"))), true, null);
file.create(new ByteArrayInputStream(routineContent.getBytes(System.getProperty("file.encoding"))), true,
null);
} else {
file.setContents(new ByteArrayInputStream(routineContent.getBytes(System.getProperty("file.encoding"))), true, false, null);
file.setContents(new ByteArrayInputStream(routineContent.getBytes(System.getProperty("file.encoding"))),
true, false, null);
}
}
}
@@ -283,13 +290,14 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
}
private Date getRefDate(RoutineItem routineItem) {
Property property = routineItem.getProperty();
if (routineItem.isBuiltIn()) {
// FIXME mhelleboid for now, routines are deleted and recreated on
// project logon
// change this code, if one day routines are updated
return routineItem.getProperty().getCreationDate();
return ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getCreatedKey());
} else {
return routineItem.getProperty().getModificationDate();
return ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getModifiedKey());
}
}
@@ -350,5 +358,4 @@ public abstract class AbstractRoutineSynchronizer implements ITalendSynchronizer
}
}
}

View File

@@ -30,6 +30,8 @@ import org.talend.core.model.properties.Property;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.core.model.repository.IRepositoryViewObject;
import org.talend.core.runtime.CoreRuntimePlugin;
import org.talend.core.runtime.repository.item.ItemProductKeys;
import org.talend.core.runtime.util.ItemDateParser;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.repository.model.IProxyRepositoryFactory;
@@ -105,9 +107,9 @@ public abstract class AbsMigrationCheckHandler implements IMigrationCheckHandler
protected MigrateItemInfo getItemInfo(Property property) {
MigrateItemInfo itemInfo = new MigrateItemInfo();
itemInfo.setAuthor(property.getAuthor().getLogin());
itemInfo.setCreated(property.getCreationDate());
itemInfo.setCreated(ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getCreatedKey()));
itemInfo.setLabel(property.getLabel());
itemInfo.setLast_modified(property.getModificationDate());
itemInfo.setLast_modified(ItemDateParser.parseAdditionalDate(property, ItemProductKeys.DATE.getModifiedKey()));
itemInfo.setType(getType());
itemInfo.setType_name(getName());
itemInfo.setVersion(property.getVersion());

View File

@@ -299,9 +299,9 @@ public class ProcessorUtilities {
return true;
}
Date modificationDate = process.getProperty().getModificationDate();
Date modificationDate = process.getModificationDate();
Date originalDate = designerCoreService.getLastGeneratedJobsDateMap().get(jobInfo.getJobId());
if (originalDate == null || modificationDate.compareTo(originalDate) != 0) {
if (originalDate == null || modificationDate == null || modificationDate.compareTo(originalDate) != 0) {
if (jobInfo.getFatherJobInfo() != null) {
jobInfo.getFatherJobInfo().setForceRegenerate(true);
}
@@ -713,7 +713,7 @@ public class ProcessorUtilities {
processor.generateCode(statistics, trace, true, option);
if (currentProcess instanceof IProcess2 && ((IProcess2) currentProcess).getProperty() != null) {
designerCoreService.getLastGeneratedJobsDateMap().put(currentProcess.getId(),
((IProcess2) currentProcess).getProperty().getModificationDate());
((IProcess2) currentProcess).getModificationDate());
}
Integer infos = new Integer(0);
infos += statistics ? GENERATED_WITH_STATS : 0;

View File

@@ -12,7 +12,6 @@
// ============================================================================
package org.talend.metadata.managment.ui.wizard;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
@@ -37,31 +36,30 @@ import org.talend.repository.ProjectManager;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.RepositoryConstants;
/**
* created by nrousseau on Jun 24, 2016
* Detailled comment
* created by nrousseau on Jun 24, 2016 Detailled comment
*
*/
public abstract class AbstractNamedWizardPage extends WizardPage {
protected IStatus nameStatus;
protected List<IRepositoryViewObject> listExistingObjects;
protected boolean retrieveNameFinished = false;
protected boolean nameModifiedByUser = false;
/**
* DOC nrousseau AbstractNamedWizardPage constructor comment.
*
* @param pageName
*/
protected AbstractNamedWizardPage(String pageName) {
super(pageName);
super(pageName);
nameStatus = createOkStatus();
}
protected static IStatus createOkStatus() {
return new Status(IStatus.OK, CoreRepositoryPlugin.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$
}
@@ -70,18 +68,15 @@ public abstract class AbstractNamedWizardPage extends WizardPage {
return new Status(severity, CoreRepositoryPlugin.PLUGIN_ID, IStatus.OK, message, null);
}
public abstract ERepositoryObjectType getRepositoryObjectType();
protected void evaluateName(String name) {
//TUP-4619 check more about '\t' name issue here and avoid NPE error
// TUP-4619 check more about '\t' name issue here and avoid NPE error
if (name == null || name.length() == 0 || StringUtils.trimToNull(name) == null) {
nameStatus = createStatus(IStatus.ERROR, Messages.getString("PropertiesWizardPage.NameEmptyError")); //$NON-NLS-1$
} else if (name.startsWith(" ") //$NON-NLS-1$
|| name.startsWith("\t") //$NON-NLS-1$
|| !Pattern.matches(RepositoryConstants.getPattern(getRepositoryObjectType()), name)
|| name.trim().contains(" ") //$NON-NLS-1$
|| !Pattern.matches(RepositoryConstants.getPattern(getRepositoryObjectType()), name) || name.trim().contains(" ") //$NON-NLS-1$
|| name.trim().contains("\t")) { // $NON-NLS-2$
nameStatus = createStatus(IStatus.ERROR, Messages.getString("PropertiesWizardPage.NameFormatError")); //$NON-NLS-1$
} else if (isKeywords(name) || "java".equalsIgnoreCase(name)) {//$NON-NLS-1$
@@ -104,22 +99,20 @@ public abstract class AbstractNamedWizardPage extends WizardPage {
if (getProperty() != null && nameStatus.getSeverity() == IStatus.OK) {
getProperty().setLabel(getPropertyLabel(StringUtils.trimToNull(name)));
getProperty().setDisplayName(StringUtils.trimToNull(name));
getProperty().setModificationDate(new Date());
}
updatePageStatus();
}
protected String getPropertyLabel(String name) {
return name;
}
public abstract Property getProperty();
protected IStatus[] getStatuses() {
return new IStatus[] { nameStatus };
};
protected void updatePageComplete() {
setMessage(findMostSevere());
setPageComplete(findMostSevere().getSeverity() != IStatus.ERROR);
@@ -154,7 +147,7 @@ public abstract class AbstractNamedWizardPage extends WizardPage {
setErrorMessage(null);
}
}
/**
*
* DOC ggu Comment method "isKeywords".
@@ -172,7 +165,7 @@ public abstract class AbstractNamedWizardPage extends WizardPage {
}
return false;
}
@SuppressWarnings("unchecked")
public boolean isValid(String itemName) {

View File

@@ -15,7 +15,6 @@ package org.talend.metadata.managment.ui.wizard;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -153,7 +152,7 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
private Item item;
private HashMap<String, Boolean> folderItems;
protected IProcessConvertService converter;// Just for the page which would like to convert self to another process.
// private Button convertBtn;// For convertation between M/R job and common job
@@ -407,7 +406,7 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
nameText = new Text(parent, SWT.BORDER);
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
nameText.setEditable(!readOnly);
createFrameworkPart(parent);
// Purpose
@@ -532,10 +531,10 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
// Added by Marvin Wang on Jan. 29, 2013.
createBottomPart(parent);
}
/**
* This method is used to create the Job type and Framework part for any properties wizard page which extends this page. Added by
* hwang on Aug. 8, 2016.
* This method is used to create the Job type and Framework part for any properties wizard page which extends this
* page. Added by hwang on Aug. 8, 2016.
*
* @param parent
*/
@@ -869,7 +868,7 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
try {
folderItems = factory.getFolderItems(type);
} catch (PersistenceException e) {
e.printStackTrace();
e.printStackTrace();
}
}
if (element instanceof Folder) {
@@ -1064,7 +1063,6 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
if (property != null && nameStatus.getSeverity() == IStatus.OK) {
property.setDisplayName(StringUtils.trimToNull(nameText.getText()));
property.setLabel(getPropertyLabel(StringUtils.trimToNull(nameText.getText())));
property.setModificationDate(new Date());
}
} else {
@@ -1095,7 +1093,6 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
commentStatus = createStatus(IStatus.WARNING, Messages.getString("PropertiesWizardPage.EmptyDescWarning")); //$NON-NLS-1$
}
property.setPurpose(StringUtils.trimToNull(purposeText.getText()));
property.setModificationDate(new Date());
updatePageStatus();
}
});
@@ -1110,7 +1107,6 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
commentStatus = createOkStatus();
}
property.setDescription(StringUtils.trimToNull(descriptionText.getText()));
property.setModificationDate(new Date());
updatePageStatus();
}
});
@@ -1127,8 +1123,6 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
version = VersionUtils.upMajor(version);
versionText.setText(version);
property.setVersion(version);
property.setCreationDate(new Date());
property.setModificationDate(new Date());
updatePageStatus();
}
});
@@ -1144,8 +1138,6 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
version = VersionUtils.upMinor(version);
versionText.setText(version);
property.setVersion(version);
property.setCreationDate(new Date());
property.setModificationDate(new Date());
updatePageStatus();
}
});
@@ -1156,7 +1148,6 @@ public abstract class PropertiesWizardPage extends AbstractNamedWizardPage {
@Override
public void modifyText(ModifyEvent e) {
property.setStatusCode(statusHelper.getStatusCode(statusText.getText()));
property.setModificationDate(new Date());
updatePageStatus();
}

View File

@@ -37,6 +37,8 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.runtime.model.emf.provider.ResourceOption;
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
import org.talend.commons.ui.runtime.exception.MessageBoxExceptionHandler;
import org.talend.commons.utils.VersionUtils;
@@ -106,6 +108,19 @@ public class MigrationToolService implements IMigrationToolService {
@Override
public void executeMigrationTasksForImport(Project project, Item item, List<MigrationTask> migrationTasksToApply,
final IProgressMonitor monitor) throws Exception {
final ResourceOption migrationOption = ResourceOption.MIGRATION;
final String optionName = migrationOption.getName();
try {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().put(optionName, migrationOption.getProvider());
delegateExecuteMigrationTasksForImport(project, item, migrationTasksToApply, monitor);
} finally {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().remove(optionName);
}
}
private void delegateExecuteMigrationTasksForImport(Project project, Item item, List<MigrationTask> migrationTasksToApply,
final IProgressMonitor monitor) throws Exception {
if (item == null || migrationTasksToApply == null) {
return;
}
@@ -166,6 +181,19 @@ public class MigrationToolService implements IMigrationToolService {
@Override
public void executeMigrationTasksForLogon(final Project project, final boolean beforeLogon, final IProgressMonitor monitorWrap) {
final ResourceOption migrationOption = ResourceOption.MIGRATION;
final String optionName = migrationOption.getName();
try {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().put(optionName, migrationOption.getProvider());
delateExecuteMigrationTasksForLogon(project, beforeLogon, monitorWrap);
} finally {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().remove(optionName);
}
}
private void delateExecuteMigrationTasksForLogon(final Project project, final boolean beforeLogon,
final IProgressMonitor monitorWrap) {
String taskDesc = "Migration tool: project [" + project.getLabel() + "] tasks"; //$NON-NLS-1$ //$NON-NLS-2$
log.trace(taskDesc);

View File

@@ -7,7 +7,6 @@ package org.talend.core.model.properties;
import java.util.Date;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EObject;
@@ -18,21 +17,21 @@ import org.eclipse.emf.ecore.EObject;
* <p>
* The following features are supported:
* <ul>
* <li>{@link org.talend.core.model.properties.Property#getId <em>Id</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getLabel <em>Label</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getPurpose <em>Purpose</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getDescription <em>Description</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getCreationDate <em>Creation Date</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getModificationDate <em>Modification Date</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getVersion <em>Version</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getStatusCode <em>Status Code</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getItem <em>Item</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getAuthor <em>Author</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getInformations <em>Informations</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getMaxInformationLevel <em>Max Information Level</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getOldStatusCode <em>Old Status Code</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getAdditionalProperties <em>Additional Properties</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getDisplayName <em>Display Name</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getId <em>Id</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getLabel <em>Label</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getPurpose <em>Purpose</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getDescription <em>Description</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getCreationDate <em>Creation Date</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getModificationDate <em>Modification Date</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getVersion <em>Version</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getStatusCode <em>Status Code</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getItem <em>Item</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getAuthor <em>Author</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getInformations <em>Informations</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getMaxInformationLevel <em>Max Information Level</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getOldStatusCode <em>Old Status Code</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getAdditionalProperties <em>Additional Properties</em>}</li>
* <li>{@link org.talend.core.model.properties.Property#getDisplayName <em>Display Name</em>}</li>
* </ul>
* </p>
*
@@ -43,13 +42,12 @@ import org.eclipse.emf.ecore.EObject;
public interface Property extends EObject {
/**
* Returns the value of the '<em><b>Id</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Id</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Id</em>' attribute isn't clear, there really should be more of a description
* here...
* If the meaning of the '<em>Id</em>' attribute isn't clear, there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Id</em>' attribute.
* @see #setId(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Id()
@@ -69,13 +67,13 @@ public interface Property extends EObject {
void setId(String value);
/**
* Returns the value of the '<em><b>Label</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Label</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Label</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Label</em>' attribute.
* @see #setLabel(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Label()
@@ -85,8 +83,9 @@ public interface Property extends EObject {
String getLabel();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getLabel <em>Label</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getLabel <em>Label</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Label</em>' attribute.
* @see #getLabel()
* @generated
@@ -94,13 +93,13 @@ public interface Property extends EObject {
void setLabel(String value);
/**
* Returns the value of the '<em><b>Purpose</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Purpose</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Purpose</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Purpose</em>' attribute.
* @see #setPurpose(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Purpose()
@@ -112,6 +111,7 @@ public interface Property extends EObject {
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getPurpose <em>Purpose</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Purpose</em>' attribute.
* @see #getPurpose()
* @generated
@@ -119,13 +119,13 @@ public interface Property extends EObject {
void setPurpose(String value);
/**
* Returns the value of the '<em><b>Description</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Description</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Description</em>' attribute isn't clear, there really should be more of a
* description here...
* If the meaning of the '<em>Description</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Description</em>' attribute.
* @see #setDescription(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Description()
@@ -135,8 +135,9 @@ public interface Property extends EObject {
String getDescription();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getDescription <em>Description</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getDescription <em>Description</em>}'
* attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Description</em>' attribute.
* @see #getDescription()
* @generated
@@ -144,63 +145,69 @@ public interface Property extends EObject {
void setDescription(String value);
/**
* Returns the value of the '<em><b>Creation Date</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Creation Date</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Creation Date</em>' attribute isn't clear, there really should be more of a
* description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Creation Date</em>' attribute.
* @see #setCreationDate(Date)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_CreationDate()
* @model unique="false" required="true"
* @generated
* @generated NOT won't be used any more
*/
@Deprecated
Date getCreationDate();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getCreationDate <em>Creation Date</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getCreationDate <em>Creation Date</em>}'
* attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Creation Date</em>' attribute.
* @see #getCreationDate()
* @generated
* @generated NOT won't be used any more
*/
@Deprecated
void setCreationDate(Date value);
/**
* Returns the value of the '<em><b>Modification Date</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Modification Date</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Modification Date</em>' attribute isn't clear, there really should be more of a
* description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Modification Date</em>' attribute.
* @see #setModificationDate(Date)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_ModificationDate()
* @model unique="false"
* @generated
* @generated NOT won't be used any more
*/
@Deprecated
Date getModificationDate();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getModificationDate <em>Modification Date</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getModificationDate
* <em>Modification Date</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Modification Date</em>' attribute.
* @see #getModificationDate()
* @generated
* @generated NOT won't be used any more
*/
@Deprecated
void setModificationDate(Date value);
/**
* Returns the value of the '<em><b>Author</b></em>' reference.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Author</b></em>' reference. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Author</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Author</em>' reference.
* @see #setAuthor(User)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Author()
@@ -212,6 +219,7 @@ public interface Property extends EObject {
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getAuthor <em>Author</em>}' reference.
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Author</em>' reference.
* @see #getAuthor()
* @generated
@@ -219,14 +227,14 @@ public interface Property extends EObject {
void setAuthor(User value);
/**
* Returns the value of the '<em><b>Informations</b></em>' containment reference list.
* The list contents are of type {@link org.talend.core.model.properties.Information}.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Informations</b></em>' containment reference list. The list contents are of type
* {@link org.talend.core.model.properties.Information}. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Informations</em>' containment reference list isn't clear,
* there really should be more of a description here...
* If the meaning of the '<em>Informations</em>' containment reference list isn't clear, there really should be more
* of a description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Informations</em>' containment reference list.
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Informations()
* @model type="org.talend.core.model.properties.Information" containment="true"
@@ -235,14 +243,14 @@ public interface Property extends EObject {
EList getInformations();
/**
* Returns the value of the '<em><b>Max Information Level</b></em>' attribute.
* The literals are from the enumeration {@link org.talend.core.model.properties.InformationLevel}.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Max Information Level</b></em>' attribute. The literals are from the enumeration
* {@link org.talend.core.model.properties.InformationLevel}. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Max Information Level</em>' attribute isn't clear,
* there really should be more of a description here...
* If the meaning of the '<em>Max Information Level</em>' attribute isn't clear, there really should be more of a
* description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Max Information Level</em>' attribute.
* @see org.talend.core.model.properties.InformationLevel
* @see #setMaxInformationLevel(InformationLevel)
@@ -253,9 +261,9 @@ public interface Property extends EObject {
InformationLevel getMaxInformationLevel();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getMaxInformationLevel <em>Max Information Level</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getMaxInformationLevel
* <em>Max Information Level</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Max Information Level</em>' attribute.
* @see org.talend.core.model.properties.InformationLevel
* @see #getMaxInformationLevel()
@@ -264,14 +272,14 @@ public interface Property extends EObject {
void setMaxInformationLevel(InformationLevel value);
/**
* Returns the value of the '<em><b>Old Status Code</b></em>' attribute.
* The default value is <code>""</code>.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Old Status Code</b></em>' attribute. The default value is <code>""</code>. <!--
* begin-user-doc -->
* <p>
* If the meaning of the '<em>Old Status Code</em>' attribute isn't clear,
* there really should be more of a description here...
* If the meaning of the '<em>Old Status Code</em>' attribute isn't clear, there really should be more of a
* description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Old Status Code</em>' attribute.
* @see #setOldStatusCode(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_OldStatusCode()
@@ -281,9 +289,9 @@ public interface Property extends EObject {
String getOldStatusCode();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getOldStatusCode <em>Old Status Code</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getOldStatusCode
* <em>Old Status Code</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Old Status Code</em>' attribute.
* @see #getOldStatusCode()
* @generated
@@ -291,30 +299,30 @@ public interface Property extends EObject {
void setOldStatusCode(String value);
/**
* Returns the value of the '<em><b>Additional Properties</b></em>' map.
* The key is of type {@link java.lang.String},
* and the value is of type {@link java.lang.String},
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Additional Properties</b></em>' map. The key is of type {@link java.lang.String}
* , and the value is of type {@link java.lang.String}, <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Additional Properties</em>' map isn't clear,
* there really should be more of a description here...
* If the meaning of the '<em>Additional Properties</em>' map isn't clear, there really should be more of a
* description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Additional Properties</em>' map.
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_AdditionalProperties()
* @model mapType="org.talend.core.model.properties.AdditionalInfoMap" keyType="java.lang.String" valueType="java.lang.String"
* @model mapType="org.talend.core.model.properties.AdditionalInfoMap" keyType="java.lang.String"
* valueType="java.lang.String"
* @generated
*/
EMap getAdditionalProperties();
/**
* Returns the value of the '<em><b>Display Name</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Display Name</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Display Name</em>' attribute isn't clear,
* there really should be more of a description here...
* If the meaning of the '<em>Display Name</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Display Name</em>' attribute.
* @see #setDisplayName(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_DisplayName()
@@ -324,9 +332,9 @@ public interface Property extends EObject {
String getDisplayName();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getDisplayName <em>Display Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getDisplayName <em>Display Name</em>}'
* attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Display Name</em>' attribute.
* @see #getDisplayName()
* @generated
@@ -334,13 +342,13 @@ public interface Property extends EObject {
void setDisplayName(String value);
/**
* Returns the value of the '<em><b>Version</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Version</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Version</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Version</em>' attribute.
* @see #setVersion(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Version()
@@ -352,6 +360,7 @@ public interface Property extends EObject {
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getVersion <em>Version</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Version</em>' attribute.
* @see #getVersion()
* @generated
@@ -359,13 +368,13 @@ public interface Property extends EObject {
void setVersion(String value);
/**
* Returns the value of the '<em><b>Status Code</b></em>' attribute.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Status Code</b></em>' attribute. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Status Code</em>' attribute isn't clear, there really should be more of a
* description here...
* If the meaning of the '<em>Status Code</em>' attribute isn't clear, there really should be more of a description
* here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Status Code</em>' attribute.
* @see #setStatusCode(String)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_StatusCode()
@@ -375,8 +384,9 @@ public interface Property extends EObject {
String getStatusCode();
/**
* Sets the value of the '{@link org.talend.core.model.properties.Property#getStatusCode <em>Status Code</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* Sets the value of the '{@link org.talend.core.model.properties.Property#getStatusCode <em>Status Code</em>}'
* attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value the new value of the '<em>Status Code</em>' attribute.
* @see #getStatusCode()
* @generated
@@ -384,14 +394,13 @@ public interface Property extends EObject {
void setStatusCode(String value);
/**
* Returns the value of the '<em><b>Item</b></em>' reference.
* It is bidirectional and its opposite is '{@link org.talend.core.model.properties.Item#getProperty <em>Property</em>}'.
* <!-- begin-user-doc -->
* Returns the value of the '<em><b>Item</b></em>' reference. It is bidirectional and its opposite is '
* {@link org.talend.core.model.properties.Item#getProperty <em>Property</em>}'. <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Item</em>' reference isn't clear, there really should be more of a description
* here...
* If the meaning of the '<em>Item</em>' reference isn't clear, there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
*
* @return the value of the '<em>Item</em>' reference.
* @see #setItem(Item)
* @see org.talend.core.model.properties.PropertiesPackage#getProperty_Item()

View File

@@ -297,7 +297,7 @@ public class DynamicContentProvider extends IntroProvider {
if (modificationDate2 == null) {
modificationDate2 = data[j - 1].getCreationDate();
}
if (modificationDate.after(modificationDate2)) {
if (modificationDate != null && modificationDate2 != null && modificationDate.after(modificationDate2)) {
IRepositoryViewObject temp = data[j - 1];
data[j - 1] = data[j];
data[j] = temp;

View File

@@ -67,6 +67,8 @@ import org.eclipse.ui.internal.wizards.datatransfer.TarException;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.exception.LoginException;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.runtime.model.emf.provider.ResourceOption;
import org.talend.commons.runtime.model.repository.ERepositoryStatus;
import org.talend.core.GlobalServiceRegister;
import org.talend.core.PluginChecker;
@@ -1000,9 +1002,16 @@ public class ImportItemsWizardPage extends WizardPage {
}
}
}
importManager.importItemRecords(monitor, resManager, checkedItemRecords, overwrite,
nodesBuilder.getAllImportItemRecords(), destinationPath);
final ResourceOption importOption = ResourceOption.ITEM_IMPORTATION;
try {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().put(importOption.getName(),
importOption.getProvider());
importManager.importItemRecords(monitor, resManager, checkedItemRecords, overwrite,
nodesBuilder.getAllImportItemRecords(), destinationPath);
} finally {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().remove(importOption.getName());
}
Display.getDefault().syncExec(new Runnable() {
@Override

View File

@@ -34,6 +34,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
@@ -480,9 +481,18 @@ public class ImportExportHandlersManager {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
// pre import
preImport(monitor, resManager, checkedItemRecords.toArray(new ImportItem[0]), allImportItemRecords);
try {
// pre import
preImport(monitor, resManager, checkedItemRecords.toArray(new ImportItem[0]),
allImportItemRecords);
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof OperationCanceledException) {
throw e; // if invalid project, with cancel
}
}
if (monitor.isCanceled()) {
return;
}
final IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
// bug 10520

View File

@@ -88,6 +88,8 @@ public class ImportItem {
private boolean isSystemItem = false;
private boolean ignore = false;
public ImportItem(IPath path) {
this.path = path;
}
@@ -138,6 +140,14 @@ public class ImportItem {
return path;
}
public boolean isIgnore() {
return ignore;
}
public void setIgnore(boolean ignore) {
this.ignore = ignore;
}
public void addError(String message) {
errors.add(message);
}
@@ -148,7 +158,7 @@ public class ImportItem {
public boolean isValid() {
// TODO mhelleboid split validation in two steps to be able to filter a valid item and avoid adding an error
return errors.isEmpty();
return errors.isEmpty() && !isIgnore();
}
/**
@@ -190,27 +200,27 @@ public class ImportItem {
* DOC hcw ImportItem class global comment. Detailled comment
*/
public enum State {
/**
* only name existed
*/
NAME_EXISTED,
/**
* only name existed
*/
NAME_EXISTED,
/**
* only id existed
*/
ID_EXISTED,
/**
* only id existed
*/
ID_EXISTED,
NON_EXISTED,
NON_EXISTED,
/**
* only one existed item with same name and same id
*/
NAME_AND_ID_EXISTED,
/**
* only one existed item with same name and same id
*/
NAME_AND_ID_EXISTED,
/**
* one existed item with same name, while another existed item with same id
*/
NAME_AND_ID_EXISTED_BOTH
/**
* one existed item with same name, while another existed item with same id
*/
NAME_AND_ID_EXISTED_BOTH
}
public State getState() {

View File

@@ -76,6 +76,8 @@ import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.exception.LoginException;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.exception.ResourceNotFoundException;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.runtime.model.emf.provider.ResourceOption;
import org.talend.commons.runtime.model.repository.ERepositoryStatus;
import org.talend.commons.ui.runtime.image.ImageUtils;
import org.talend.commons.utils.VersionUtils;
@@ -166,7 +168,6 @@ import org.talend.repository.localprovider.exceptions.IncorrectFileException;
import org.talend.repository.localprovider.i18n.Messages;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.RepositoryConstants;
import orgomg.cwm.foundation.businessinformation.BusinessinformationPackage;
/**
@@ -1107,8 +1108,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
}
/**
* @see org.talend.core.model.repository.factories.IRepositoryFactory#readProject(java.lang.String, java.lang.String,
* java.lang.String)
* @see org.talend.core.model.repository.factories.IRepositoryFactory#readProject(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
public Project[] readProject() throws PersistenceException {
@@ -1651,7 +1652,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
}
@Override
public void deleteObjectPhysical(Project project, IRepositoryViewObject objToDelete, boolean isDeleteOnRemote) throws PersistenceException {
public void deleteObjectPhysical(Project project, IRepositoryViewObject objToDelete, boolean isDeleteOnRemote)
throws PersistenceException {
deleteObjectPhysical(project, objToDelete, null, isDeleteOnRemote);
}
@@ -1680,7 +1682,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
|| currentVersion.getRepositoryObjectType() == ERepositoryObjectType.JOBLET
|| currentVersion.getRepositoryObjectType() == ERepositoryObjectType.SPARK_JOBLET
|| currentVersion.getRepositoryObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
if (coreSerivce.isAlreadyBuilt(project)) {
Project currentProject = ProjectManager.getInstance().getCurrentProject();
if (coreSerivce.isAlreadyBuilt(project) && currentProject != null) {
if (currentVersion.getProperty() != null) {
coreSerivce.removeItemRelations(currentVersion.getProperty().getItem());
}
@@ -2348,7 +2351,6 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
xmiResourceManager.getAffectedResources(resourceSet, item.getProperty());
computePropertyMaxInformationLevel(item.getProperty());
item.getProperty().setModificationDate(new Date());
Resource itemResource = null;
Resource screenshotResource = null;
EClass eClass = item.eClass();
@@ -2569,7 +2571,7 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
xmlResource.setID(connectionItem.getConnection(), EcoreUtil.generateUUID());
}
}
return newItem;
} catch (IOException e) {
// e.printStackTrace();
@@ -2593,7 +2595,7 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
newRefItem.setContent(byarray);
}
}
private void copyIcon(Item originalItem, Item newItem) throws PersistenceException {
if (!(newItem instanceof JobletProcessItem)) {
return;
@@ -2673,6 +2675,17 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
@Override
public void create(Project project, Item item, IPath path, boolean... isImportItem) throws PersistenceException {
final ResourceOption creatation = ResourceOption.CREATATION;
final String optionName = creatation.getName();
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().put(optionName, creatation.getProvider());
try {
delegateCreate(project, item, path, isImportItem);
} finally {
EmfResourcesFactoryReader.INSTANCE.getSaveOptionsProviders().remove(optionName);
}
}
private void delegateCreate(Project project, Item item, IPath path, boolean... isImportItem) throws PersistenceException {
computePropertyMaxInformationLevel(item.getProperty());
if (item.getProperty().getVersion() == null) {
@@ -2682,14 +2695,6 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
item.getProperty().setAuthor(getRepositoryContext().getUser());
}
if (item.getProperty().getCreationDate() == null) {
item.getProperty().setCreationDate(new Date());
}
if (item.getProperty().getModificationDate() == null) {
item.getProperty().setModificationDate(item.getProperty().getCreationDate());
}
ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
if (item.getState() != null) {
itemState.setDeleted(item.getState().isDeleted());
@@ -2896,6 +2901,7 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
if (isImportItem.length == 0 || !isImportItem[0]) {
saveProject(project);
}
}
private List<Resource> getReferenceFilesResources(Item item, Resource propertyResource, boolean needLoad) {
@@ -3158,9 +3164,9 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
if (!doesLoggedUserExist() && project.isMainProject()) {
createUser(project);
}
initProjectRepository(project, null);
IProject project2 = ResourceUtils.getProject(project);
createFolders(project2, project.getEmfProject());
synchronizeRoutines(project2);
@@ -3240,8 +3246,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
@Override
public List<org.talend.core.model.properties.Project> getReferencedProjects(Project project) {
String parentBranch = getRepositoryContext().getFields()
.get(IProxyRepositoryFactory.BRANCH_SELECTION + "_" + getRepositoryContext().getProject().getTechnicalLabel());
String parentBranch = getRepositoryContext().getFields().get(
IProxyRepositoryFactory.BRANCH_SELECTION + "_" + getRepositoryContext().getProject().getTechnicalLabel());
List<org.talend.core.model.properties.Project> refProjectList = new ArrayList<org.talend.core.model.properties.Project>();
for (ProjectReference refProject : project.getProjectReferenceList()) {
if (ProjectManager.validReferenceProject(parentBranch, refProject)) {
@@ -3471,7 +3477,7 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
}
@Override
public void executeMigrations(Project mainProject, boolean beforeLogon, SubMonitor monitorWrap) throws PersistenceException{
public void executeMigrations(Project mainProject, boolean beforeLogon, SubMonitor monitorWrap) throws PersistenceException {
IMigrationToolService service = (IMigrationToolService) GlobalServiceRegister.getDefault().getService(
IMigrationToolService.class);
service.executeMigrationTasksForLogon(mainProject, beforeLogon, monitorWrap);
@@ -3520,8 +3526,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
// nothing to do
}
public void initProjectRepository(Project project,String branchForMainProject) throws PersistenceException {
public void initProjectRepository(Project project, String branchForMainProject) throws PersistenceException {
}
protected void notifyProjectReload(org.talend.core.model.properties.Project project) {

View File

@@ -0,0 +1,408 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.runtime.repository.item;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Date;
import java.util.Map;
import org.eclipse.emf.common.util.EMap;
import org.junit.BeforeClass;
import org.junit.Test;
import org.talend.commons.utils.VersionUtils;
import org.talend.core.GlobalServiceRegister;
import org.talend.core.model.properties.Project;
import org.talend.core.model.properties.PropertiesFactory;
import org.talend.core.model.properties.Property;
import org.talend.core.ui.branding.IBrandingService;
import org.talend.repository.ProjectManager;
/**
* DOC ggu class global comment. Detailled comment
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ItemProductValuesHelperTest {
static IBrandingService brandingService = null;
@BeforeClass
public static void setup() {
brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
assertNotNull(brandingService);
}
@Test
public void test_existed_null() {
assertFalse(ItemProductValuesHelper.existed(null));
}
@Test
public void test_existed_empty() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
assertFalse(ItemProductValuesHelper.existed(prop));
}
@Test
public void test_existed_others() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
additionalProp.put("ABC", "XYZ");
assertFalse(ItemProductValuesHelper.existed(prop));
}
@Test
public void test_existed_modifiedKey() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
additionalProp.put(ItemProductKeys.FULLNAME.getModifiedKey(), "TOS");
assertTrue("Don't exist modified or created product full name", ItemProductValuesHelper.existed(prop));
}
@Test
public void test_existed_createdKey() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
additionalProp.put(ItemProductKeys.FULLNAME.getCreatedKey(), "TOS");
assertTrue("Don't exist modified or created product full name", ItemProductValuesHelper.existed(prop));
}
@Test
public void test_existed_importKey() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
additionalProp.put(ItemProductKeys.FULLNAME.getImportKey(), "TOS");
assertFalse("Only import product full name is invalid", ItemProductValuesHelper.existed(prop));
}
@Test
public void test_existed_all() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
additionalProp.put(ItemProductKeys.FULLNAME.getModifiedKey(), "TP");
additionalProp.put(ItemProductKeys.FULLNAME.getCreatedKey(), "TOP");
additionalProp.put(ItemProductKeys.FULLNAME.getImportKey(), "TP");
assertTrue("Don't exist modified or created product full name", ItemProductValuesHelper.existed(prop));
}
@Test
public void test_setValuesWhenCreate() {
doTestSetValuesWhenCreate(new Date());
}
@Test
public void test_setValuesWhenCreate_nullDate() {
doTestSetValuesWhenCreate(null);
}
private void doTestSetValuesWhenCreate(Date date) {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
boolean set = ItemProductValuesHelper.setValuesWhenCreate(prop, date);
assertTrue(set);
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getCreatedKey()), equalTo(brandingService.getFullProductName()));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getCreatedKey()), equalTo(VersionUtils.getDisplayVersion()));
assertThat(additionalProp.get(ItemProductKeys.DATE.getCreatedKey()), anything());
}
@Test
public void test_setValuesWhenModify() {
doTestSetValuesWhenModify(new Date());
}
@Test
public void test_setValuesWhenModify_nullDate() {
doTestSetValuesWhenModify(null);
}
private void doTestSetValuesWhenModify(Date date) {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
boolean set = ItemProductValuesHelper.setValuesWhenModify(prop, date);
assertTrue(set);
EMap additionalProp = prop.getAdditionalProperties();
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getModifiedKey()), equalTo(brandingService.getFullProductName()));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getModifiedKey()), equalTo(VersionUtils.getDisplayVersion()));
assertThat(additionalProp.get(ItemProductKeys.DATE.getModifiedKey()), anything());
}
@Test
public void test_setValuesWhenMigrate_exist() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
prop.getAdditionalProperties().put(ItemProductKeys.FULLNAME.getModifiedKey(), "xxxx");
boolean set = ItemProductValuesHelper.setValuesWhenMigrate(prop, null);
assertFalse(set);
}
@Test
public void test_setValuesWhenMigrate_nullDate() {
String productFullname = "Talend Open Studio for Big Data";
String productVersion = "6.5.1.20171110_1941";
Project project = PropertiesFactory.eINSTANCE.createProject();
project.setProductVersion("Talend Open Studio for Big Data-6.5.1.20171110_1941");
Property prop = PropertiesFactory.eINSTANCE.createProperty();
boolean set = ItemProductValuesHelper.setValuesWhenMigrate(prop, project);
assertTrue(set);
EMap additionalProp = prop.getAdditionalProperties();
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getCreatedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getCreatedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getCreatedKey()), anything());
assertThat(prop.getCreationDate(), nullValue());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getModifiedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getModifiedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getModifiedKey()), anything());
assertThat(prop.getModificationDate(), nullValue());
}
@Test
public void test_setValuesWhenMigrate_nullProject() {
org.talend.core.model.general.Project currentProject = ProjectManager.getInstance().getCurrentProject();
assertNotNull(currentProject);
Project project = currentProject.getEmfProject();
Map<String, String> productValues = ItemProductValuesHelper.parseProduct(project.getProductVersion());
assertFalse(productValues.isEmpty());
String productFullname = productValues.keySet().iterator().next();
String productVersion = productValues.get(productFullname);
//
Property prop = PropertiesFactory.eINSTANCE.createProperty();
boolean set = ItemProductValuesHelper.setValuesWhenMigrate(prop, null);
assertTrue(set);
EMap additionalProp = prop.getAdditionalProperties();
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getCreatedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getCreatedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getCreatedKey()), anything());
assertThat(prop.getCreationDate(), nullValue());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getModifiedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getModifiedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getModifiedKey()), anything());
assertThat(prop.getModificationDate(), nullValue());
}
@Test
public void test_setValuesWhenMigrate() {
String productFullname = "Talend Open Studio for Big Data";
String productVersion = "6.5.1.20171110_1941";
Project project = PropertiesFactory.eINSTANCE.createProject();
project.setProductVersion("Talend Open Studio for Big Data-6.5.1.20171110_1941");
Property prop = PropertiesFactory.eINSTANCE.createProperty();
Date createdDate = new Date();
try {
Thread.sleep(100);// make sure the date is different
} catch (InterruptedException e) {
//
}
Date modifiedDate = new Date();
prop.setCreationDate(createdDate);
prop.setModificationDate(modifiedDate);
boolean set = ItemProductValuesHelper.setValuesWhenMigrate(prop, project);
assertTrue(set);
EMap additionalProp = prop.getAdditionalProperties();
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getCreatedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getCreatedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getCreatedKey()),
equalTo(ItemProductValuesHelper.DATEFORMAT.format(createdDate)));
assertThat(prop.getCreationDate(), nullValue());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getModifiedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getModifiedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getModifiedKey()),
equalTo(ItemProductValuesHelper.DATEFORMAT.format(modifiedDate)));
assertThat(prop.getModificationDate(), nullValue());
}
@Test
public void test_setValuesWhenImport_null() {
boolean set = ItemProductValuesHelper.setValuesWhenImport(null, null);
assertFalse(set);
Property prop = PropertiesFactory.eINSTANCE.createProperty();
set = ItemProductValuesHelper.setValuesWhenImport(prop, null);
assertFalse(set);
Project project = PropertiesFactory.eINSTANCE.createProject();
set = ItemProductValuesHelper.setValuesWhenImport(null, project);
assertFalse(set);
}
@Test
public void test_setValuesWhenImport_empty() {
Property prop = PropertiesFactory.eINSTANCE.createProperty();
Project project = PropertiesFactory.eINSTANCE.createProject();
project.setProductVersion("");
boolean set = ItemProductValuesHelper.setValuesWhenImport(prop, project);
assertFalse(set);
}
// @Test
public void test_setValuesWhenImport_tosdq() {
// not productversion for TOS DQ
fail("There is no product version value");
// doTest_SetValuesForImport("","","");
}
@Test
public void test_setValuesWhenImport_withMigrating() {
String productFullname = "Talend Open Studio for Big Data";
String productVersion = "6.5.1.20171110_1941";
Project project = PropertiesFactory.eINSTANCE.createProject();
project.setProductVersion("Talend Open Studio for Big Data-6.5.1.20171110_1941");
Property prop = PropertiesFactory.eINSTANCE.createProperty();
boolean set = ItemProductValuesHelper.setValuesWhenImport(prop, project);
assertTrue(set);
EMap additionalProp = prop.getAdditionalProperties();
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getImportKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getImportKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getImportKey()), anything());
assertThat(prop.getCreationDate(), nullValue());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getCreatedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getCreatedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getCreatedKey()), anything());
assertThat(prop.getCreationDate(), nullValue());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getModifiedKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getModifiedKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getModifiedKey()), anything());
assertThat(prop.getModificationDate(), nullValue());
}
@Test
public void test_setValuesWhenImport_withoutMigrating() {
String productFullname = "Talend Open Studio for Big Data";
String productVersion = "6.5.1.20171110_1941";
Project project = PropertiesFactory.eINSTANCE.createProject();
project.setProductVersion("Talend Open Studio for Big Data-6.5.1.20171110_1941");
Property prop = PropertiesFactory.eINSTANCE.createProperty();
EMap additionalProp = prop.getAdditionalProperties();
additionalProp.put(ItemProductKeys.FULLNAME.getModifiedKey(), "XXXX"); // set flag to avoid migrating
boolean set = ItemProductValuesHelper.setValuesWhenImport(prop, project);
assertTrue(set);
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getImportKey()), equalTo(productFullname));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getImportKey()), equalTo(productVersion));
assertThat(additionalProp.get(ItemProductKeys.DATE.getImportKey()), anything());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getCreatedKey()), nullValue());
assertThat(additionalProp.get(ItemProductKeys.VERSION.getCreatedKey()), nullValue());
assertThat(additionalProp.get(ItemProductKeys.DATE.getCreatedKey()), nullValue());
assertThat(prop.getCreationDate(), nullValue());
assertThat(additionalProp.get(ItemProductKeys.FULLNAME.getModifiedKey()), equalTo("XXXX"));
assertThat(additionalProp.get(ItemProductKeys.VERSION.getModifiedKey()), nullValue());
assertThat(additionalProp.get(ItemProductKeys.DATE.getModifiedKey()), anything());
assertThat(prop.getModificationDate(), nullValue());
}
@Test
public void test_parseProduct_empty() {
Map<String, String> values = ItemProductValuesHelper.parseProduct(null);
assertTrue(values.isEmpty());
values = ItemProductValuesHelper.parseProduct("");
assertTrue(values.isEmpty());
}
@Test
public void test_parseProduct_invalid() {
doTestParseProduct("ABCD", "ABCD", null);
doTestParseProduct("Talend Open Studio for Big Data+6.5.1.20171110_1941",
"Talend Open Studio for Big Data+6.5.1.20171110_1941", null);
doTestParseProduct("Talend Open Studio for Big Data_6.5.1.20171110_1941",
"Talend Open Studio for Big Data_6.5.1.20171110_1941", null);
}
@Test
public void test_parseProduct_valid() {
doTestParseProduct("ABCD-XYZ", "ABCD", "XYZ");
doTestParseProduct("ABCD-XYZ-123", "ABCD", "XYZ-123");
doTestParseProduct("Talend Open Studio for Big Data-6.5.1.20171110_1941", "Talend Open Studio for Big Data",
"6.5.1.20171110_1941");
doTestParseProduct("Talend Open Studio for Big Data-6.5.1.20171110-1941", "Talend Open Studio for Big Data",
"6.5.1.20171110-1941");
doTestParseProduct("Talend Open Studio-3.2.3.r35442", "Talend Open Studio", "3.2.3.r35442");
doTestParseProduct("Talend Open Studio for Data Integration-5.3.2.r113626", "Talend Open Studio for Data Integration",
"5.3.2.r113626");
}
@Test
public void test_parseProduct_patch() {
doTestParseProduct("Talend Data Fabric-6.3.1.20171030_0901-patch", "Talend Data Fabric", "6.3.1.20171030_0901-patch");
}
@Test
public void test_parseProduct_snapshot() {
doTestParseProduct("Talend Open Studio for Big Data-6.5.1.20171110_1941-SNAPSHOT", "Talend Open Studio for Big Data",
"6.5.1.20171110_1941-SNAPSHOT");
}
private void doTestParseProduct(String value, String productFullname, String productVersion) {
Map<String, String> values = ItemProductValuesHelper.parseProduct(value);
assertFalse(values.isEmpty());
assertEquals(1, values.size());
String actualProductFullname = values.keySet().iterator().next();
String actualProductVersion = values.get(actualProductFullname);
assertEquals(productFullname, actualProductFullname);
if (productVersion != null) {
assertEquals(productVersion, actualProductVersion);
} else {
assertNull(actualProductVersion);
}
}
}