Skip to content

Commit

Permalink
[2109] Use descriptors on ProgressMonitoring instead of diagrams
Browse files Browse the repository at this point in the history
Bug: 2109
Change-Id: I89c437f45bc11cd9fc0accd01f06e78bfa415b08
Signed-off-by: Philippe DUL <philippe.dul@thalesgroup.com>
  • Loading branch information
pdulth committed Jun 27, 2018
1 parent 96fda5d commit d78da0f
Show file tree
Hide file tree
Showing 38 changed files with 811 additions and 871 deletions.
Expand Up @@ -33,7 +33,8 @@ Require-Bundle: org.eclipse.ui,
org.polarsys.capella.core.commandline.core,
org.polarsys.capella.core.af.integration,
org.polarsys.capella.common.libraries,
org.polarsys.capella.core.sirius.analysis
org.polarsys.capella.core.sirius.analysis,
org.polarsys.capella.core.data.business.queries
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Expand Down
Expand Up @@ -197,10 +197,6 @@
class="org.polarsys.capella.core.data.migration.contribution.DAnnotationDescriptorContribution">
</migrationContribution>

<migrationContribution
class="org.polarsys.capella.core.data.migration.contribution.FixDAnnotationsContribution">
</migrationContribution>

<migrationContribution
class="org.polarsys.capella.core.data.migration.contribution.ActivateDiagramFiltersContribution">
</migrationContribution>
Expand Down
@@ -1,100 +1,185 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.data.migration.contribution;

import java.util.HashMap;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.osgi.util.NLS;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.polarsys.capella.common.ef.ExecutionManager;
import org.polarsys.capella.core.data.migration.Activator;
import org.polarsys.capella.core.data.migration.context.MigrationContext;
import org.polarsys.capella.core.diagram.helpers.DAnnotationHelper;

/**
* This class migrates annotation from DRepresentation to DRepresentationDescriptor
*/
public class DAnnotationDescriptorContribution extends AbstractMigrationContribution {

public static final String allocating_diagrams = "INITIALIZATION_REALIZING"; //$NON-NLS-1$

public static final String allocated_diagrams = "INITIALIZATION_REALIZED"; //$NON-NLS-1$

HashMap<String, DRepresentationDescriptor> descriptors = new HashMap<String, DRepresentationDescriptor>();
HashMap<String, DRepresentation> diagrams = new HashMap<String, DRepresentation>();

@Override
public void dispose(MigrationContext context) {
super.dispose(context);
descriptors.clear();
diagrams.clear();
}

@Override
public void unaryMigrationExecute(EObject currentElement, MigrationContext context) {
super.unaryMigrationExecute(currentElement, context);

if (currentElement instanceof DRepresentationDescriptor) {
if (((DRepresentationDescriptor) currentElement).getRepPath() != null) {
descriptors.put(((DRepresentationDescriptor) currentElement).getRepPath().getResourceURI().fragment(),
((DRepresentationDescriptor) currentElement));
}
}

if (currentElement instanceof DRepresentation) {
diagrams.put(((DRepresentation)currentElement).getUid(), (DRepresentation) currentElement);
}
}

@Override
public void postMigrationExecute(ExecutionManager executionManager, ResourceSet resourceSet,
MigrationContext context) {
super.postMigrationExecute(executionManager, resourceSet, context);

int i = 0;
for (String xmiId : diagrams.keySet()) {
DRepresentation diagram = diagrams.get(xmiId);
try {
DRepresentationDescriptor descriptor = descriptors.get(diagram.getUid());
if (descriptor != null) {
if (migrate(diagram, descriptor)) {
i++;
}
}
} catch (Exception e) {
// Just a preventive catch while migration
}
}
if (i > 0) {
IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID, NLS.bind(org.polarsys.capella.core.data.migration.contribution.Messages.MigrationAction_AnnotationMigration, context.getName(), i));
Activator.getDefault().getLog().log(status);
}
}

private boolean migrate(DRepresentation diagram, DRepresentationDescriptor descriptor) {
boolean result = false;

//Remove annotations from Initialize From Existing Diagram, since never used and tooled.
if (DAnnotationHelper.removeAnnotation(allocating_diagrams, diagram)) {
result = true;
}
if (DAnnotationHelper.removeAnnotation(allocated_diagrams, diagram)) {
result = true;
}
return result;
}

}
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.data.migration.contribution;

import java.util.Collection;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.osgi.util.NLS;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.description.DAnnotation;
import org.polarsys.capella.common.ef.ExecutionManager;
import org.polarsys.capella.common.tools.report.config.registry.ReportManagerRegistry;
import org.polarsys.capella.common.tools.report.util.IReportManagerDefaultComponents;
import org.polarsys.capella.common.tools.report.util.LogExt;
import org.polarsys.capella.core.business.queries.IBusinessQuery;
import org.polarsys.capella.core.business.queries.capellacore.BusinessQueriesProvider;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.capellacore.CapellacorePackage;
import org.polarsys.capella.core.data.capellacore.EnumerationPropertyLiteral;
import org.polarsys.capella.core.data.migration.Activator;
import org.polarsys.capella.core.data.migration.context.MigrationContext;
import org.polarsys.capella.core.diagram.helpers.DAnnotationHelper;
import org.polarsys.capella.core.diagram.helpers.IRepresentationAnnotationConstants;
import org.polarsys.capella.core.model.handler.helpers.CapellaAdapterHelper;
import org.polarsys.capella.core.model.handler.helpers.RepresentationHelper;

/**
* This class migrates annotation from DRepresentation to DRepresentationDescriptor
*/
public class DAnnotationDescriptorContribution extends AbstractMigrationContribution {

public static final String allocating_diagrams = "INITIALIZATION_REALIZING"; //$NON-NLS-1$

public static final String allocated_diagrams = "INITIALIZATION_REALIZED"; //$NON-NLS-1$

HashMap<String, DRepresentationDescriptor> descriptors = new HashMap<String, DRepresentationDescriptor>();
HashMap<String, DRepresentation> diagrams = new HashMap<String, DRepresentation>();

@Override
public void dispose(MigrationContext context) {
super.dispose(context);
descriptors.clear();
diagrams.clear();
}

@Override
public void unaryMigrationExecute(EObject currentElement, MigrationContext context) {
super.unaryMigrationExecute(currentElement, context);

if (currentElement instanceof DRepresentationDescriptor) {
if (((DRepresentationDescriptor) currentElement).getRepPath() != null) {
descriptors.put(((DRepresentationDescriptor) currentElement).getRepPath().getResourceURI().fragment(),
((DRepresentationDescriptor) currentElement));
}
}

if (currentElement instanceof DRepresentation) {
diagrams.put(((DRepresentation) currentElement).getUid(), (DRepresentation) currentElement);
}
}

@Override
public void postMigrationExecute(ExecutionManager executionManager, ResourceSet resourceSet,
MigrationContext context) {
super.postMigrationExecute(executionManager, resourceSet, context);

int i = 0;
for (String uid : diagrams.keySet()) {
DRepresentation diagram = diagrams.get(uid);
try {
DRepresentationDescriptor descriptor = descriptors.get(diagram.getUid());
if (descriptor != null) {
int nb = migrate(diagram, descriptor);
i += nb;
}
} catch (Exception e) {
// Just a preventive catch while migration
}
}
if (i > 0) {
Logger logger = ReportManagerRegistry.getInstance().subscribe(IReportManagerDefaultComponents.DEFAULT);
IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID,
NLS.bind(org.polarsys.capella.core.data.migration.contribution.Messages.MigrationAction_AnnotationMigration,
context.getName(), i));
LogExt.log(logger, status);
}
}

private int migrate(DRepresentation diagram, DRepresentationDescriptor descriptor) {
int result = 0;

// Remove annotations from Initialize From Existing Diagram, since never used and tooled.
if (DAnnotationHelper.removeAnnotation(allocating_diagrams, diagram)) {
result++;
}
if (DAnnotationHelper.removeAnnotation(allocated_diagrams, diagram)) {
result++;
}

DAnnotation annotation = null;

// Move progress status annotations towards the descriptor
annotation = RepresentationHelper.getAnnotation(IRepresentationAnnotationConstants.NotVisibleInDoc, diagram);
if (annotation != null) {
RepresentationHelper.removeAnnotation(IRepresentationAnnotationConstants.NotVisibleInDoc, diagram);
DAnnotationHelper.createAnnotation(IRepresentationAnnotationConstants.NotVisibleInDoc, descriptor);
result++;
}

annotation = RepresentationHelper.getAnnotation(IRepresentationAnnotationConstants.NotVisibleInLM, diagram);
if (annotation != null) {
RepresentationHelper.removeAnnotation(IRepresentationAnnotationConstants.NotVisibleInLM, diagram);
DAnnotationHelper.createAnnotation(IRepresentationAnnotationConstants.NotVisibleInLM, descriptor);
result++;
}

annotation = RepresentationHelper.getAnnotation(IRepresentationAnnotationConstants.StatusReview, diagram);
if (annotation != null) {
DAnnotation created = DAnnotationHelper.createAnnotation(IRepresentationAnnotationConstants.StatusReview,
descriptor);
if (annotation.getDetails() != null) {
created.getDetails().putAll(annotation.getDetails());
}
RepresentationHelper.removeAnnotation(IRepresentationAnnotationConstants.StatusReview, diagram);
result++;
}

annotation = RepresentationHelper.getAnnotation(IRepresentationAnnotationConstants.ProgressStatus, diagram);
if (annotation != null) {
if (annotation.getDetails() != null) {
String statusValue = annotation.getDetails().get(IRepresentationAnnotationConstants.PROGRESS_VALUE_KEYVALUE);

try {
IBusinessQuery query = BusinessQueriesProvider.getInstance().getContribution(
CapellacorePackage.Literals.CAPELLA_ELEMENT, CapellacorePackage.Literals.CAPELLA_ELEMENT__STATUS);

if (null != query) {
Collection<EObject> statuses = query
.getAvailableElements((CapellaElement) CapellaAdapterHelper.resolveSemanticObject(descriptor, true));
EnumerationPropertyLiteral literal = null;
for (EObject review : statuses) {
if (review instanceof EnumerationPropertyLiteral
&& ((EnumerationPropertyLiteral) review).getLabel().equals(statusValue)) {
literal = (EnumerationPropertyLiteral) review;
}
}
if (literal != null) {
DAnnotation created = DAnnotationHelper
.createAnnotation(IRepresentationAnnotationConstants.ProgressStatus, descriptor);
created.getReferences().clear();
created.getReferences().add(literal);
result++;

} else {
Logger logger = ReportManagerRegistry.getInstance().subscribe(IReportManagerDefaultComponents.DEFAULT);
IStatus status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, NLS.bind(
org.polarsys.capella.core.data.migration.contribution.Messages.MigrationAction_MissingStatusMigration,
descriptor.getName(), statusValue));
LogExt.log(logger, status);
}
}
} catch (Exception e) {
// Just a preventive catch while migration if migration occurs on an invalid descriptor
}
}
RepresentationHelper.removeAnnotation(IRepresentationAnnotationConstants.StatusReview, diagram);
}
return result;
}

}

This file was deleted.

Expand Up @@ -22,6 +22,7 @@ public class Messages extends NLS {
public static String MigrationAction_ConfirmationDialog_ToggleMessage;
public static String MigrationAction_UidMigration;
public static String MigrationAction_AnnotationMigration;
public static String MigrationAction_MissingStatusMigration;

static {
// initialize resource bundle
Expand Down
Expand Up @@ -12,3 +12,4 @@ MigrationAction_ConfirmationDialog_Message=It is recommended to backup the model
MigrationAction_ConfirmationDialog_ToggleMessage=Backup models before the migration
MigrationAction_UidMigration={1} ID of diagrams have been updated successfully
MigrationAction_AnnotationMigration={1} annotations of diagrams have been updated successfully
MigrationAction_MissingStatusMigration=Representation ''{0}'' was associated to Progress Monitoring status ''{1}'' but this status has been deleted since.

0 comments on commit d78da0f

Please sign in to comment.