Skip to content

Commit

Permalink
Merge pull request #779 from eclipse-passage/572650-7
Browse files Browse the repository at this point in the history
572650 upgrade `licenses` domain model
  • Loading branch information
eparovyshnaya authored May 20, 2021
2 parents 3887216 + 2f1acbb commit 4ec6a1b
Show file tree
Hide file tree
Showing 51 changed files with 1,976 additions and 1,543 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ private LicenseGrant grant(Condition condition) {
LicensesFactory licenseFactory = LicensesFactory.eINSTANCE;
LicenseGrant grant = licenseFactory.createLicenseGrant();
grant.setIdentifier(condition.identifier());
grant.setFeatureIdentifier(condition.feature());
grant.setMatchVersion(condition.versionMatch().version());
grant.setMatchRule(condition.versionMatch().rule().identifier());
grant.getFeature().setIdentifier(condition.feature());
grant.getFeature().setVersion(condition.versionMatch().version());
grant.getFeature().setMatchingRule(condition.versionMatch().rule().identifier());
grant.setCapacity(1);
grant.setConditionExpression(condition.evaluationInstructions().expression());
grant.setConditionType(condition.evaluationInstructions().type().identifier());
grant.setValidFrom(date(condition, ValidityPeriodClosed::from));
grant.setValidUntil(date(condition, ValidityPeriodClosed::to));
grant.getUserAuthentication().setExpression(condition.evaluationInstructions().expression());
grant.getUserAuthentication().setType(condition.evaluationInstructions().type().identifier());
((org.eclipse.passage.lic.licenses.model.api.ValidityPeriodClosed) grant.getValid())
.setFrom(date(condition, ValidityPeriodClosed::from));
((org.eclipse.passage.lic.licenses.model.api.ValidityPeriodClosed) grant.getValid())
.setUntil(date(condition, ValidityPeriodClosed::to));
return grant;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.emf.migration;

import java.util.List;
import java.util.function.Function;

import org.eclipse.emf.ecore.EObject;

/**
* Helps to ensure that inner data structures exists for the given EObject
*
* @since 2.0
*/
public interface EnsureStructure extends Function<EObject, List<EObject>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.BasicResourceHandler;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.passage.lic.emf.migration.EFeatureRoutes;
import org.eclipse.passage.lic.emf.migration.EnsureStructure;
import org.eclipse.passage.lic.internal.emf.migration.RecognizeFeatures;

/**
* Adds hooks for migrating legacy data
Expand All @@ -43,5 +46,11 @@ public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> op
resource.getEObjectToExtensionMap().entrySet().forEach(this::convertEntry);
}

protected abstract void convertEntry(Entry<EObject, AnyType> entry);
protected void convertEntry(Entry<EObject, AnyType> entry) {
new RecognizeFeatures(entry.getValue(), attributes(), structures()).mixed(entry.getKey());
}

protected abstract EFeatureRoutes attributes();

protected abstract EnsureStructure structures();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.emf.ecore.util.FeatureMap.Entry;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.passage.lic.emf.migration.EFeatureRoutes;
import org.eclipse.passage.lic.emf.migration.EnsureStructure;

/**
* @since 2.0
Expand All @@ -36,16 +37,18 @@ public final class RecognizeFeatures {

private final AnyType any;
private final EFeatureRoutes features;
private final EnsureStructure ensure;

public RecognizeFeatures(AnyType any, EFeatureRoutes features) {
public RecognizeFeatures(AnyType any, EFeatureRoutes features, EnsureStructure ensure) {
Objects.requireNonNull(any, "ApplyFeatureMap::any"); //$NON-NLS-1$
Objects.requireNonNull(features, "ApplyFeatureMap::features"); //$NON-NLS-1$
this.any = any;
this.features = features;
this.ensure = ensure;
}

@SuppressWarnings("unchecked")
public RecognizeFeatures mixed(EObject object) {
public void mixed(EObject object) {
EList<EReference> references = object.eClass().getEAllReferences();
for (Iterator<Entry> iterator = any.getMixed().iterator(); iterator.hasNext();) {
Entry entry = iterator.next();
Expand All @@ -60,15 +63,17 @@ public RecognizeFeatures mixed(EObject object) {
if (value instanceof AnyType) {
AnyType child = (AnyType) value;
EObject created = type.getEPackage().getEFactoryInstance().create(type);
new RecognizeFeatures(child, features).attributes(created);
RecognizeFeatures restore = new RecognizeFeatures(child, features, ensure);
restore.attributes(created);
ensure.apply(created).forEach(restore::attributes);
if (feature.isMany()) {
((List<EObject>) object.eGet(feature)).add(created);
} else {
object.eSet(feature, created);
}
}
}
return this;
ensure.apply(object).forEach(this::attributes);
}

private Optional<EStructuralFeature> candidate(EObject object, Entry entry,
Expand All @@ -77,7 +82,7 @@ private Optional<EStructuralFeature> candidate(EObject object, Entry entry,
.filter(all::contains);
}

public RecognizeFeatures attributes(EObject object) {
public void attributes(EObject object) {
EList<EAttribute> attributes = object.eClass().getEAllAttributes();
for (Iterator<Entry> iterator = any.getAnyAttribute().iterator(); iterator.hasNext();) {
Entry entry = iterator.next();
Expand All @@ -92,7 +97,6 @@ public RecognizeFeatures attributes(EObject object) {
String.valueOf(entry.getValue()));
object.eSet(feature, value);
}
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
*******************************************************************************/
package org.eclipse.passage.lic.internal.features.model.migration;

import java.util.Map.Entry;
import java.util.Collections;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.passage.lic.emf.migration.DelegateClassifiers;
import org.eclipse.passage.lic.emf.migration.EClassRoutes;
import org.eclipse.passage.lic.emf.migration.EFeatureRoutes;
import org.eclipse.passage.lic.emf.migration.EnsureStructure;
import org.eclipse.passage.lic.emf.migration.SimpleClassRoutes;
import org.eclipse.passage.lic.emf.migration.SimpleFeatureRoutes;
import org.eclipse.passage.lic.emf.xmi.MigratingResourceHandler;
import org.eclipse.passage.lic.features.model.meta.FeaturesPackage;

Expand All @@ -32,8 +33,13 @@ protected void ensureMigrations() {
}

@Override
protected void convertEntry(Entry<EObject, AnyType> entry) {
// not yet needed
protected EFeatureRoutes attributes() {
return new SimpleFeatureRoutes();
}

@Override
protected EnsureStructure structures() {
return e -> Collections.emptyList();
}

private void migrate033() {
Expand Down
46 changes: 23 additions & 23 deletions bundles/org.eclipse.passage.lic.licenses.ecore/model/licenses.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="LicensePlanFeatureDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.LicensePlanFeatureDescriptor"
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="LicensePackDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.LicensePackDescriptor"
<eClassifiers xsi:type="ecore:EClass" name="PersonalLicensePackDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.PersonalLicensePackDescriptor"
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="LicenseGrantDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.LicenseGrantDescriptor"
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="UserRefDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.UserRefDescriptor"
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="ProductRefDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.ProductRefDescriptor"
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="UserRefDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.UserRefDescriptor"
<eClassifiers xsi:type="ecore:EClass" name="FeatureRefDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.FeatureRefDescriptor"
abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="CompanyRefDescriptor" instanceClassName="org.eclipse.passage.lic.licenses.CompanyRefDescriptor"
abstract="true" interface="true"/>
Expand Down Expand Up @@ -53,15 +55,12 @@
eType="#//FloatingLicensePack" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="LicensePlanFeature" eSuperTypes="#//LicensePlanFeatureDescriptor">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="featureIdentifier" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="matchVersion" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString" defaultValueLiteral="0.0.0"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="matchRule" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="feature" lowerBound="1"
eType="#//FeatureRef" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="licensePlan" lowerBound="1"
eType="#//LicensePlan"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="PersonalLicensePack" eSuperTypes="#//LicensePackDescriptor">
<eClassifiers xsi:type="ecore:EClass" name="PersonalLicensePack" eSuperTypes="#//PersonalLicensePackDescriptor">
<eStructuralFeatures xsi:type="ecore:EReference" name="license" lowerBound="1"
eType="#//PersonalLicenseRequisites" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="grants" upperBound="-1"
Expand All @@ -70,19 +69,12 @@
<eClassifiers xsi:type="ecore:EClass" name="LicenseGrant" eSuperTypes="#//LicenseGrantDescriptor">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="identifier" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
iD="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="featureIdentifier" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="matchVersion" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString" defaultValueLiteral="0.0.0"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="matchRule" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="validFrom" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDate"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="validUntil" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDate"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="conditionType" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="conditionExpression" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="feature" lowerBound="1"
eType="#//FeatureRef" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="valid" lowerBound="1" eType="#//ValidityPeriod"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="userAuthentication" lowerBound="1"
eType="#//EvaluationInstructions" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="capacity" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="1"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="licensePack" lowerBound="1"
Expand Down Expand Up @@ -117,16 +109,24 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="company" lowerBound="1"
eType="#//CompanyRef" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="UserRef" eSuperTypes="#//UserRefDescriptor">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="identifier" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ProductRef" eSuperTypes="#//ProductRefDescriptor">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="identifier" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="UserRef" eSuperTypes="#//UserRefDescriptor">
<eClassifiers xsi:type="ecore:EClass" name="FeatureRef" eSuperTypes="#//FeatureRefDescriptor">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="identifier" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="matchingRule" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CompanyRef" eSuperTypes="#//CompanyRefDescriptor">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="identifier" lowerBound="1"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions bundles/org.eclipse.passage.lic.licenses.edit/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ _UI_UserRef_name_feature = Name
_UI_CompanyRef_identifier_feature = Identifier
_UI_CompanyRef_name_feature = Name
_UI_CompanyRef_info_feature = Info
_UI_PersonalLicensePackDescriptor_type = Personal License Pack Descriptor
_UI_FeatureRefDescriptor_type = Feature Ref Descriptor
_UI_FeatureRef_type = Feature Ref
_UI_LicensePlanFeature_feature_feature = Feature
_UI_LicenseGrant_feature_feature = Feature
_UI_LicenseGrant_valid_feature = Valid
_UI_LicenseGrant_userAuthentication_feature = User Authentication
_UI_FeatureRef_identifier_feature = Identifier
_UI_FeatureRef_version_feature = Version
_UI_FeatureRef_matchingRule_feature = Matching Rule
Expand Down
Loading

0 comments on commit 4ec6a1b

Please sign in to comment.