- remove duplicate classes ItemReportRecorder/ItemsReportUtil/MigrationReportHelper/MigrationReportRecorder (#5782)

This commit is contained in:
Wei Hua
2022-12-12 17:19:25 +08:00
committed by GitHub
parent 421dde4b8e
commit bde2e73cfa
10 changed files with 8 additions and 612 deletions

View File

@@ -1,149 +0,0 @@
// ============================================================================
//
// Copyright (C) 2006-2021 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.designer.maven.migration.common;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.exception.PersistenceException;
import org.talend.core.GlobalServiceRegister;
import org.talend.core.model.properties.Item;
import org.talend.core.model.properties.Property;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.core.ui.ITestContainerCoreService;
/**
* DOC jding class global comment. Detailled comment
*/
public class ItemReportRecorder {
protected Item item;
protected String detailMessage;
public String getItemType() {
String type = "";
ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
if (itemType != null) {
if (ERepositoryObjectType.getAllTypesOfTestContainer().contains(itemType)) {
Item parentJobItem = getTestCaseParentJobItem(item);
if (parentJobItem != null) {
ERepositoryObjectType parentJobType = ERepositoryObjectType.getItemType(parentJobItem);
if (parentJobType != null) {
String parentTypePath = getCompleteObjectTypePath(parentJobType);
if (StringUtils.isNotBlank(parentTypePath)) {
type = parentTypePath + "/";
}
}
}
type += itemType;
} else {
type = getCompleteObjectTypePath(itemType);
}
}
return type;
}
public String getItemPath() {
String path = "";
StringBuffer buffer = new StringBuffer();
ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
if (ERepositoryObjectType.getAllTypesOfTestContainer().contains(itemType)) {
StringBuffer testcaseBuffer = new StringBuffer();
Item parentJobItem = getTestCaseParentJobItem(item);
if (parentJobItem != null) {
if (parentJobItem.getState() != null && StringUtils.isNotBlank(parentJobItem.getState().getPath())) {
testcaseBuffer.append(parentJobItem.getState().getPath()).append("/");
}
testcaseBuffer.append(parentJobItem.getProperty() != null ? parentJobItem.getProperty().getLabel() : "");
if (StringUtils.isNotBlank(testcaseBuffer.toString())) {
buffer.append(testcaseBuffer.toString()).append("/");
}
}
} else {
if (item.getState() != null && StringUtils.isNotBlank(item.getState().getPath())) {
buffer.append(item.getState().getPath()).append("/");
}
}
Property property = item.getProperty();
if (property != null) {
buffer.append(property.getLabel() + "_" + property.getVersion());
}
path = buffer.toString();
return path;
}
private Item getTestCaseParentJobItem(Item testcaseItem) {
Item parentJobItem = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerCoreService.class)) {
ITestContainerCoreService testcaseService = GlobalServiceRegister.getDefault()
.getService(ITestContainerCoreService.class);
if (testcaseService != null) {
try {
parentJobItem = testcaseService.getParentJobItem(item);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
return parentJobItem;
}
private String getCompleteObjectTypePath(ERepositoryObjectType itemType) {
ERepositoryObjectType rootItemType = itemType;
if (ERepositoryObjectType.JDBC != null && ERepositoryObjectType.JDBC.equals(rootItemType)) {
rootItemType = ERepositoryObjectType.METADATA_CONNECTIONS;
}
List<String> typeLabels = new ArrayList<String>();
findOutCompleteTypePath(rootItemType, typeLabels);
StringBuffer buffer = new StringBuffer();
if (!typeLabels.isEmpty()) {
for (int i = 0; i < typeLabels.size(); i++) {
if (i != 0) {
buffer.append("/");
}
buffer.append(typeLabels.get(i));
}
}
return buffer.toString();
}
private void findOutCompleteTypePath(ERepositoryObjectType type, List<String> typeLabels) {
ERepositoryObjectType parentType = ERepositoryObjectType.findParentType(type);
if (parentType != null) {
findOutCompleteTypePath(parentType, typeLabels);
}
typeLabels.add(type.getLabel());
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public String getDetailMessage() {
return detailMessage;
}
public void setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
}
}

View File

@@ -1,81 +0,0 @@
// ============================================================================
//
// Copyright (C) 2006-2021 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.designer.maven.migration.common;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.Path;
import org.talend.core.utils.TalendQuoteUtils;
/**
* DOC jding class global comment. Detailled comment
*/
public class ItemsReportUtil {
public static boolean generateReportFile(File reportFile, String header, List<String> records) throws Exception {
boolean generateDone = false;
BufferedWriter printWriter = null;
try {
File parentFolder = new Path(reportFile.getAbsolutePath()).removeLastSegments(1).toFile();
// File parentFolder = new File(parentPath);
if (!parentFolder.exists()) {
parentFolder.mkdirs();
}
if (!reportFile.exists()) {
reportFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(reportFile);
fos.write(new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF });
OutputStreamWriter outputWriter = new OutputStreamWriter(fos, "UTF-8");
printWriter = new BufferedWriter(outputWriter);
printWriter.write(header);
printWriter.newLine();
for (String recordStr : records) {
printWriter.write(recordStr);
printWriter.newLine();
}
printWriter.flush();
generateDone = true;
} finally {
if (printWriter != null) {
printWriter.close();
}
}
return generateDone;
}
public static String handleColumnQuotes(String text) {
String quoteMark = TalendQuoteUtils.QUOTATION_MARK;
text = StringUtils.isBlank(text) ? "" : text;
if (text.contains(quoteMark)) {
// replace to double quote surround
text = text.replace(quoteMark, quoteMark + quoteMark);
}
return quoteMark + text + quoteMark;
}
public static String getCurrentTimeString() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String time = dateFormat.format(new Date());
return time;
}
}

View File

@@ -1,177 +0,0 @@
// ============================================================================
//
// Copyright (C) 2006-2021 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.designer.maven.migration.common;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.osgi.service.prefs.BackingStoreException;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.core.PluginChecker;
import org.talend.core.model.properties.Item;
import org.talend.core.model.properties.Property;
import org.talend.migration.IProjectMigrationTask;
/**
* DOC jding class global comment. Detailled comment
*/
public class MigrationReportHelper {
private static final String COMMA = ",";
private static final String PLUGIN_ID = "org.talend.designer.maven";
private static final String DO_NOT_SHOW_PREF_KEY = "talend.migrationReportDialog.doNotShowAgain";
private static final String MIGRATION_REPORT_HEAD = "Task name,Task description,Item type,Path to migrated item,Migration details";
private static final MigrationReportHelper instance = new MigrationReportHelper();
public static MigrationReportHelper getInstance() {
return instance;
}
private String reportGeneratedPath = "";
private Set<String> taskItemRecords = new HashSet<String>();
private List<MigrationReportRecorder> migrationReportRecorders = new ArrayList<MigrationReportRecorder>();
public void generateMigrationReport(String projectTecName) {
if (migrationReportRecorders == null || migrationReportRecorders.isEmpty()) {
return;
}
if (!PluginChecker.isTIS()) {
clearRecorders();
return;
}
File exportFolder = null;
File reportFile = null;
try {
String currentTime = getCurrentTime();
String filePath = getReportExportFolder(currentTime) + "/" + getReportFileName(currentTime, projectTecName);
reportGeneratedPath = filePath;
reportFile = new File(filePath);
List<String> recordLines = new ArrayList<String>();
for (MigrationReportRecorder record : migrationReportRecorders) {
StringBuffer buffer = new StringBuffer();
buffer.append(ItemsReportUtil.handleColumnQuotes(record.getTaskClassName())).append(COMMA);
buffer.append(ItemsReportUtil.handleColumnQuotes(record.getTaskDescription())).append(COMMA);
buffer.append(ItemsReportUtil.handleColumnQuotes(record.getItemType())).append(COMMA);
buffer.append(ItemsReportUtil.handleColumnQuotes(record.getItemPath())).append(COMMA);
buffer.append(ItemsReportUtil.handleColumnQuotes(record.getDetailMessage()));
recordLines.add(buffer.toString());
}
ItemsReportUtil.generateReportFile(reportFile, MIGRATION_REPORT_HEAD, recordLines);
} catch (Exception e) {
ExceptionHandler.process(e);
if (reportFile != null && reportFile.exists()) {
reportFile.delete();
}
if (exportFolder != null && exportFolder.exists()) {
exportFolder.delete();
}
} finally {
migrationReportRecorders.clear();
taskItemRecords.clear();
}
}
public boolean isRequireDefaultRecord(IProjectMigrationTask task, Item item) {
boolean require = true;
if (task.getOrder() != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(task.getOrder());
int year = calendar.get(Calendar.YEAR);
if (year <= 2016) {
return false;
}
}
if (item.getProperty() != null) {
Property property = item.getProperty();
String key = task.getId() + "_" + property.getId() + "_" + property.getVersion();
if (taskItemRecords.contains(key)) {
return false;
}
}
return require;
}
private String getCurrentTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String time = dateFormat.format(new Date());
return time;
}
private String getReportExportFolder(String time) {
String folderName = "migrationReport" + "_" + time;
String path = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/report/" + folderName;
return path;
}
private String getReportFileName(String time, String projectTecName) {
String fileName = time + "_" + projectTecName + "_" + "Migration" + "_" + "Report.csv";
return fileName;
}
public static void storeDoNotShowAgainPref(boolean selected) {
IScopeContext scopeContext = ConfigurationScope.INSTANCE;
IEclipsePreferences pref = scopeContext.getNode(PLUGIN_ID);
pref.putBoolean(DO_NOT_SHOW_PREF_KEY, selected);
try {
pref.flush();
} catch (BackingStoreException e) {
ExceptionHandler.process(e);
}
}
public static boolean isReportDialogDisable() {
IScopeContext scopeContext = ConfigurationScope.INSTANCE;
IEclipsePreferences pref = scopeContext.getNode(PLUGIN_ID);
return pref.getBoolean(DO_NOT_SHOW_PREF_KEY, false);
}
public void addRecorder(MigrationReportRecorder recorder) {
if (recorder != null) {
migrationReportRecorders.add(recorder);
if (recorder.getItem() != null && recorder.getItem().getProperty() != null) {
Property property = recorder.getItem().getProperty();
taskItemRecords.add(recorder.getTask().getId() + "_" + property.getId() + "_" + property.getVersion());
}
}
}
public void clearRecorders() {
reportGeneratedPath = "";
migrationReportRecorders.clear();
taskItemRecords.clear();
}
public String getReportGeneratedPath() {
return reportGeneratedPath;
}
}

View File

@@ -1,197 +0,0 @@
// ============================================================================
//
// Copyright (C) 2006-2021 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.designer.maven.migration.common;
import org.apache.commons.lang.StringUtils;
import org.talend.core.model.components.ComponentUtilities;
import org.talend.core.model.properties.Item;
import org.talend.core.utils.TalendQuoteUtils;
import org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.migration.IProjectMigrationTask;
/**
* DOC jding class global comment. Detailled comment
*/
public class MigrationReportRecorder extends ItemReportRecorder {
private IProjectMigrationTask task;
private MigrationOperationType operationType;
private NodeType node;
private String paramName;
private String oldValue;
private String newValue;
public enum MigrationOperationType {
ADD,
MODIFY,
DELETE
}
public MigrationReportRecorder(IProjectMigrationTask task, Item item) {
super();
this.task = task;
this.item = item;
}
public MigrationReportRecorder(IProjectMigrationTask task, MigrationOperationType operationType, Item item, NodeType node,
String paramName, String oldValue, String newValue) {
super();
this.task = task;
this.operationType = operationType;
this.item = item;
this.node = node;
this.paramName = paramName;
this.oldValue = oldValue;
this.newValue = newValue;
}
public MigrationReportRecorder(IProjectMigrationTask task, Item item, String detailMessage) {
super();
this.task = task;
this.item = item;
this.detailMessage = detailMessage;
}
public String getTaskClassName() {
return task.getClass().getSimpleName();
}
public String getTaskDescription() {
String description = "";
if (StringUtils.isNotBlank(task.getDescription())) {
description = task.getDescription();
}
return description;
}
public String getDetailMessage() {
String details = detailMessage;
if (StringUtils.isNotBlank(detailMessage)) {
return details;
}
if (operationType == null || StringUtils.isBlank(paramName)) {
details = getTaskClassName() + " task is applied";
return details;
}
StringBuffer detailBuffer = new StringBuffer();
if (node != null) {
// migration for node, e.g. tRESTClient component "tRESTClient_2":
detailBuffer.append(node.getComponentName()).append(" component ");
ElementParameterType uniqueName = ComponentUtilities.getNodeProperty(node, "UNIQUE_NAME");
detailBuffer.append(TalendQuoteUtils.addQuotes(uniqueName.getValue())).append(":");
} else {
// migration for item, e.g. context item "testContext":
detailBuffer.append(getItemType() + " item ")
.append(TalendQuoteUtils.addQuotes(item.getProperty().getLabel())).append(":");
}
detailBuffer.append(paramName).append(" was ");
switch (operationType) {
case ADD:
detailBuffer.append("added");
if (StringUtils.isNotBlank(newValue)) {
detailBuffer.append(" with ").append(newValue);
}
break;
case MODIFY:
detailBuffer.append("changed");
if (StringUtils.isNotBlank(oldValue)) {
detailBuffer.append(" from ").append(oldValue);
}
if (StringUtils.isNotBlank(newValue)) {
detailBuffer.append(" to ").append(newValue);
}
break;
case DELETE:
detailBuffer.append("deleted");
break;
default:
break;
}
details = detailBuffer.toString();
return details;
}
/**
* Getter for task.
*
* @return the task
*/
public IProjectMigrationTask getTask() {
return task;
}
/**
* Sets the task.
*
* @param task the task to set
*/
public void setTask(IProjectMigrationTask task) {
this.task = task;
}
/**
* Sets the operationType.
*
* @param operationType the operationType to set
*/
public void setOperationType(MigrationOperationType operationType) {
this.operationType = operationType;
}
/**
* Sets the node.
*
* @param node the node to set
*/
public void setNode(NodeType node) {
this.node = node;
}
/**
* Sets the paramName.
*
* @param paramName the paramName to set
*/
public void setParamName(String paramName) {
this.paramName = paramName;
}
/**
* Sets the oldValue.
*
* @param oldValue the oldValue to set
*/
public void setOldValue(String oldValue) {
this.oldValue = oldValue;
}
/**
* Sets the newValue.
*
* @param newValue the newValue to set
*/
public void setNewValue(String newValue) {
this.newValue = newValue;
}
}

View File

@@ -18,8 +18,8 @@ import org.talend.core.repository.utils.ConvertJobsUtil;
import org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.designer.maven.migration.common.MigrationReportHelper;
import org.talend.designer.maven.migration.common.MigrationReportRecorder;
import org.talend.migration.MigrationReportHelper;
import org.talend.migration.MigrationReportRecorder;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.IRepositoryService;

View File

@@ -13,8 +13,8 @@ import org.talend.core.model.properties.Item;
import org.talend.core.model.properties.ProcessItem;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.designer.maven.migration.common.MigrationReportRecorder;
import org.talend.designer.runprocess.ItemCacheManager;
import org.talend.migration.MigrationReportRecorder;
import org.talend.repository.ProjectManager;
/*

View File

@@ -11,7 +11,7 @@ import org.talend.core.model.components.filters.NameComponentFilter;
import org.talend.core.model.properties.Item;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.designer.maven.migration.common.MigrationReportRecorder;
import org.talend.migration.MigrationReportRecorder;
/*
* (non-Javadoc)

View File

@@ -17,8 +17,8 @@ import org.talend.core.repository.model.ProxyRepositoryFactory;
import org.talend.core.runtime.process.TalendProcessArgumentConstant;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.designer.maven.migration.common.MigrationReportRecorder;
import org.talend.designer.runprocess.ItemCacheManager;
import org.talend.migration.MigrationReportRecorder;
import org.talend.repository.ProjectManager;
/*

View File

@@ -11,7 +11,7 @@ import org.talend.core.model.components.filters.NameComponentFilter;
import org.talend.core.model.properties.Item;
import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.designer.maven.migration.common.MigrationReportRecorder;
import org.talend.migration.MigrationReportRecorder;
/*
* Data service SOAP = Job with "tESBProviderRequest"

View File

@@ -1,6 +1,7 @@
package org.talend.designer.maven.tools;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -15,14 +16,13 @@ import org.eclipse.swt.widgets.Display;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.core.model.general.Project;
import org.talend.core.repository.model.ProxyRepositoryFactory;
import org.talend.designer.maven.migration.common.MigrationReportHelper;
import org.talend.designer.maven.migration.tasks.CorrectBuildTypeForDIJobMigrationTask;
import org.talend.designer.maven.migration.tasks.CorrectBuildTypeForDsRestMigrationTask;
import org.talend.designer.maven.migration.tasks.CorrectBuildTypeForRoutesMigrationTask;
import org.talend.designer.maven.migration.tasks.CorrectBuildTypeForSOAPServiceJobMigrationTask;
import org.talend.designer.maven.migration.tasks.ICorrectBuildTypeMigrationTask;
import org.talend.migration.IMigrationTask;
import org.talend.migration.IProjectMigrationTask;
import org.talend.migration.MigrationReportHelper;
import org.talend.repository.ProjectManager;
import org.talend.repository.RepositoryWorkUnit;