Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 572650 - upgrade licenses domain model #774

Merged
merged 11 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.Failure;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.eclipse.passage.lic.licenses.model.api.LicensePack;
import org.eclipse.passage.lic.licenses.model.api.PersonalLicensePack;

public final class Conditions implements Supplier<NetResponse> {

Expand Down Expand Up @@ -57,11 +57,11 @@ public NetResponse get() {
return encodedPack(pack(conditions.data().get()));
}

private NetResponse encodedPack(LicensePack pack) {
private NetResponse encodedPack(PersonalLicensePack pack) {
return new EncodedResponse<EObject>(pack, data).get();
}

private LicensePack pack(Collection<ConditionPack> conditions) {
private PersonalLicensePack pack(Collection<ConditionPack> conditions) {
return new PersonalLicenseGenerated(//
data.product().get(), //
data.user().get(), //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
* Copyright (c) 2020, 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
Expand All @@ -22,11 +22,13 @@
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.conditions.Condition;
import org.eclipse.passage.lic.internal.api.conditions.ValidityPeriodClosed;
import org.eclipse.passage.lic.internal.licenses.model.EmptyPersonalLicensePack;
import org.eclipse.passage.lic.licenses.model.api.LicenseGrant;
import org.eclipse.passage.lic.licenses.model.api.LicensePack;
import org.eclipse.passage.lic.licenses.model.api.PersonalLicensePack;
import org.eclipse.passage.lic.licenses.model.meta.LicensesFactory;

final class PersonalLicenseGenerated implements Supplier<LicensePack> {
@SuppressWarnings("restriction")
final class PersonalLicenseGenerated implements Supplier<PersonalLicensePack> {

private final LicensedProduct product;
private final String user;
Expand All @@ -39,19 +41,18 @@ final class PersonalLicenseGenerated implements Supplier<LicensePack> {
}

@Override
public LicensePack get() {
LicensePack pack = LicensesFactory.eINSTANCE.createLicensePack();
pack.setIdentifier(generated());
pack.setIssueDate(new Date());
pack.setPlanIdentifier("ignored"); //$NON-NLS-1$
pack.setProductIdentifier(product.identifier());
pack.setProductVersion(product.version());
pack.setUserFullName(user);
pack.setUserIdentifier(user);
pack.setRequestIdentifier(generated());
public PersonalLicensePack get() {
PersonalLicensePack pack = new EmptyPersonalLicensePack().get();
pack.getLicense().setIdentifier(generated());
pack.getLicense().setIssueDate(new Date());
pack.getLicense().setPlan("ignored"); //$NON-NLS-1$
pack.getLicense().getProduct().setIdentifier(product.identifier());
pack.getLicense().getProduct().setVersion(product.version());
pack.getLicense().getUser().setName(user);
pack.getLicense().getUser().setIdentifier(user);
conditions.stream()//
.map(this::grant)//
.forEach(pack.getLicenseGrants()::add);
.forEach(pack.getGrants()::add);
return pack;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.emf.migration;
package org.eclipse.passage.lic.emf.migration;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.passage.lic.internal.emf.migration.DelegateEPackage;
import org.eclipse.passage.lic.internal.emf.migration.DelegatingEFactory;
import org.eclipse.passage.lic.internal.emf.migration.DelegatingEPackage;

/**
* @since 2.0
Expand All @@ -31,19 +33,19 @@ public DelegateClassifiers(String uri) {
this.uri = uri;
}

public void delegate(EPackage delegate, Iterable<String> classifierNames) {
public void delegate(EClassRoutes routes) {
DelegatingEPackage delegating = new DelegateEPackage().apply(uri);
DelegatingEFactory factory = delegating.getDelegatingEFactory();
Map<EClass, EClass> delegated = new HashMap<>();
for (String name : classifierNames) {
EClassifier eClassifier = delegate.getEClassifier(name);
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
EClass key = EcoreUtil.copy(eClass);
delegated.put(key, eClass);
}
Map<String, EClass> defined = routes.defined();
for (Entry<String, EClass> entry : defined.entrySet()) {
EClass to = entry.getValue();
EClass from = EcoreUtil.copy(to);
from.setName(entry.getKey());
delegated.put(from, to);
delegating.getEClassifiers().add(from);
factory.delegateEClass(to.getEPackage().getEFactoryInstance(), from, to);
}
delegating.getEClassifiers().addAll(delegated.keySet());
delegating.getDelegatingEFactory().addEClassDelegate(delegate.getEFactoryInstance(), delegated);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* 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.Map;
import java.util.Optional;

import org.eclipse.emf.ecore.EClass;

/**
* @since 2.0
*/
public interface EClassRoutes {

void define(String found, EClass destination);

Map<String, EClass> defined();

Optional<EClass> route(String found);

public static final class Smart implements EClassRoutes {

private final EClassRoutes delegate;

public Smart(EClassRoutes delegate) {
this.delegate = delegate;
}

@Override
public void define(String found, EClass destination) {
delegate.define(found, destination);
}

public void define(EClass destination) {
delegate.define(destination.getName(), destination);
}

@Override
public Map<String, EClass> defined() {
return delegate.defined();
}

@Override
public Optional<EClass> route(String found) {
return delegate.route(found);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
package org.eclipse.passage.lic.emf.migration;

import java.util.Optional;
import java.util.function.Function;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
* @since 2.0
*/
public interface EFeatureRoutes extends Function<String, Optional<EStructuralFeature>> {
public interface EFeatureRoutes {

void add(String found, EStructuralFeature destination);
void define(String found, EStructuralFeature destination);

Optional<EStructuralFeature> route(String found, EClass scope);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* 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.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

import org.eclipse.emf.ecore.EClass;

/**
*
* @since 2.0
*
*/
public final class SimpleClassRoutes implements EClassRoutes {

private final Map<String, EClass> map;

public SimpleClassRoutes() {
map = new LinkedHashMap<>();
}

@Override
public void define(String found, EClass destination) {
map.put(found, destination);
}

@Override
public Map<String, EClass> defined() {
return new LinkedHashMap<>(map);
}

@Override
public Optional<EClass> route(String found) {
return Optional.ofNullable(map.get(found));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;
import java.util.Optional;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
Expand All @@ -32,13 +33,27 @@ public SimpleFeatureRoutes() {
}

@Override
public Optional<EStructuralFeature> apply(String found) {
return Optional.ofNullable(map.get(found));
public Optional<EStructuralFeature> route(String found, EClass context) {
Optional<EStructuralFeature> candidate = Optional.ofNullable(map.get(key(found, context)));
if (candidate.isPresent()) {
return candidate;
}
for (EClass upper : context.getEAllSuperTypes()) {
Optional<EStructuralFeature> inherited = route(found, upper);
if (inherited.isPresent()) {
return inherited;
}
}
return Optional.empty();
}

@Override
public void add(String found, EStructuralFeature destination) {
map.put(found, destination);
public void define(String found, EStructuralFeature destination) {
map.put(destination.getEContainingClass().getName() + '.' + found, destination);
}

private String key(String found, EClass scope) {
return scope.getName() + '.' + found;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.eclipse.passage.lic.internal.emf.migration;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

import org.eclipse.emf.common.util.EList;
Expand All @@ -22,19 +20,17 @@ public DelegatingEPackage apply(String nsUri) {
return (DelegatingEPackage) existing;
} else {
DelegatingEPackage delegating = new DelegatingEPackage(nsUri);
DelegatingEFactory factory = delegating.getDelegatingEFactory();
if (existing != null) {
Map<EClass, EClass> wrapped = new HashMap<>();
EList<EClassifier> classifiers = existing.getEClassifiers();
for (EClassifier eClassifier : classifiers) {
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
EClass key = EcoreUtil.copy(eClass);
wrapped.put(key, eClass);
EClass to = (EClass) eClassifier;
EClass from = EcoreUtil.copy(to);
delegating.getEClassifiers().add(from);
factory.delegateEClass(existing.getEFactoryInstance(), from, to);
}
}
delegating.getEClassifiers().addAll(wrapped.keySet());
DelegatingEFactory factory = delegating.getDelegatingEFactory();
factory.addEClassDelegate(existing.getEFactoryInstance(), wrapped);
}
EPackage.Registry.INSTANCE.put(nsUri, delegating);
return delegating;
Expand Down
Loading