Skip to content

Commit

Permalink
564419 API revision | conditions | Path condition miner
Browse files Browse the repository at this point in the history
 - half-reimplement xmi condition transport

Signed-off-by: elena.parovyshnaya <elena.parovyshnaya@gmail.com>
  • Loading branch information
eparovyshnaya committed Jul 6, 2020
1 parent 7f9cc69 commit 34605d9
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public final class ConfigurationResidentConditions extends LocalConditions {

public ConfigurationResidentConditions(MiningEquipment equipment, Consumer<LicensingException> handler) {
super(new StringServiceId("installation-conditions"), equipment, handler); //$NON-NLS-1$
super(new StringServiceId("configuration-conditions"), equipment, handler); //$NON-NLS-1$
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public Collection<Condition> read(InputStream input) throws IOException {
return new JsonObjectMapper().get().readValue(input, ConditionPack.class).conditions;
}

@SuppressWarnings("resource")
@Override
public void write(Collection<Condition> conditions, OutputStream output) throws IOException {
Objects.requireNonNull(conditions, "JsonConditionTransport::write::conditions"); //$NON-NLS-1$
Objects.requireNonNull(output, "JsonConditionTransport::write::output"); //$NON-NLS-1$
output.write(new JsonObjectMapper().get().writeValueAsBytes(new ConditionPack(conditions)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.passage.lic.licenses.model;bundle-version="0.0.0"
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/*.xml
Export-Package: org.eclipse.passage.lic.internal.licenses.migration;x-internal:=true
Export-Package: org.eclipse.passage.lic.internal.licenses.migration;x-internal:=true,
org.eclipse.passage.lic.internal.licenses.migration.tobemoved;x-internal:=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (c) 2020 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.internal.licenses.migration.tobemoved;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.passage.lic.api.conditions.LicensingCondition;
import org.eclipse.passage.lic.base.conditions.LicensingConditions;
import org.eclipse.passage.lic.internal.api.conditions.Condition;
import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;
import org.eclipse.passage.lic.internal.api.conditions.ValidityPeriodClosed;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionTransport;
import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType;
import org.eclipse.passage.lic.internal.base.conditions.BaseCondition;
import org.eclipse.passage.lic.internal.base.conditions.BaseEvaluationInstructions;
import org.eclipse.passage.lic.internal.base.conditions.BaseValidityPeriodClosed;
import org.eclipse.passage.lic.internal.base.conditions.BaseVersionMatch;
import org.eclipse.passage.lic.internal.base.conditions.MatchingRuleForIdentifier;
import org.eclipse.passage.lic.licenses.LicenseGrantDescriptor;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;

@SuppressWarnings("restriction")
public final class XmiConditionTransport implements ConditionTransport {

private final ContentType type = new ContentType.Xml();

@Override
public ContentType id() {
return type;
}

@Override
public Collection<Condition> read(InputStream input) throws IOException {
Resource resource = new XMIResourceImpl();
resource.load(input, new HashMap<>());
return resource.getContents().stream() //
.filter(LicensePackDescriptor.class::isInstance) //
.map(LicensePackDescriptor.class::cast) //
.map(LicensePackDescriptor::getLicenseGrants) //
.flatMap(i -> StreamSupport.stream(i.spliterator(), false)) //
.map(this::condition) //
.collect(Collectors.toList());
}

private Condition condition(LicenseGrantDescriptor descriptor) {
return new BaseCondition(//
descriptor.getFeatureIdentifier(), //
new BaseVersionMatch(descriptor.getMatchVersion(), //
new MatchingRuleForIdentifier(descriptor.getMatchRule()).get()), //
new BaseValidityPeriodClosed(//
descriptor.getValidFrom(), //
descriptor.getValidUntil()), //
new BaseEvaluationInstructions(//
new EvaluationType.Of(descriptor.getConditionType()), //
descriptor.getConditionExpression()));
}

@Override
public void write(Collection<Condition> conditions, OutputStream output) throws IOException {
Resource resource = new XMIResourceImpl();
EList<EObject> contents = resource.getContents();
for (Condition condition : conditions) {
LicensingCondition conditionDescriptor = condition(condition);
if (conditionDescriptor instanceof EObject) {
EObject eObject = (EObject) conditionDescriptor;
contents.add(eObject);
}
}
resource.save(output, new HashMap<>());
}

// FIXME: severe error here: none of'em are EObject! Find a way to construct
// true-emf LicenseGrantDescriptors
private LicensingCondition condition(Condition condition) {
LicensingCondition lic = LicensingConditions.create(//
condition.feature(), //
condition.versionMatch().version(), //
condition.versionMatch().rule().identifier(), //
((ValidityPeriodClosed) condition.validityPeriod()).from(), //
((ValidityPeriodClosed) condition.validityPeriod()).to(), //
condition.evaluationInstructions().type().identifier(), //
condition.evaluationInstructions().expression());
throw new UnsupportedOperationException();
}

}
3 changes: 2 additions & 1 deletion bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="3.8.0",
org.eclipse.passage.lic.equinox;bundle-version="0.6.0",
org.eclipse.passage.lic.hc;bundle-version="0.5.300",
org.eclipse.passage.lic.json;bundle-version="0.5.300",
org.eclipse.passage.lic.bc;bundle-version="0.5.100"
org.eclipse.passage.lic.bc;bundle-version="0.5.100",
org.eclipse.passage.lic.licenses.migration
Service-Component: OSGI-INF/*.xml
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.passage.seal.internal.demo;x-internal:=true
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements;
import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteConditions;
import org.eclipse.passage.lic.internal.json.tobemoved.JsonConditionTransport;
import org.eclipse.passage.lic.internal.licenses.migration.tobemoved.XmiConditionTransport;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

Expand Down Expand Up @@ -75,7 +76,8 @@ final class SealedAccessCycleConfiguration implements AccessCycleConfiguration {
alarm)//
));
transports = new ReadOnlyRegistry<>(Arrays.asList(//
new JsonConditionTransport()//
new JsonConditionTransport(), //
new XmiConditionTransport() // FIXME: does not do `writing`
));
codecs = new ReadOnlyRegistry<>(Arrays.asList(//
new BcStreamCodec(product) //
Expand Down

0 comments on commit 34605d9

Please sign in to comment.