-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 571190 build the solution on Framework services host
personal license transport is extended with filtering abilities Signed-off-by: eparovyshnaya <[email protected]>
- Loading branch information
1 parent
aec33bc
commit 75d1f5c
Showing
3 changed files
with
135 additions
and
82 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
.../eclipse/passage/lic/internal/licenses/migration/tobemoved/BaseXmiConditionTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* 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.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.xmi.XMLResource; | ||
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; | ||
import org.eclipse.passage.lic.internal.api.EvaluationType; | ||
import org.eclipse.passage.lic.internal.api.conditions.Condition; | ||
import org.eclipse.passage.lic.internal.api.conditions.MatchingRule; | ||
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.MatchingRuleDefault; | ||
import org.eclipse.passage.lic.internal.base.conditions.MatchingRuleForIdentifier; | ||
import org.eclipse.passage.lic.internal.licenses.migration.LicensesResourceHandler; | ||
import org.eclipse.passage.lic.licenses.model.api.LicenseGrant; | ||
import org.eclipse.passage.lic.licenses.model.api.LicensePack; | ||
|
||
abstract class BaseXmiConditionTransport implements ConditionTransport { | ||
|
||
private final ContentType type = new ContentType.Xml(); | ||
private final Predicate<LicensePack> filter; | ||
|
||
protected BaseXmiConditionTransport() { | ||
this(p -> true); | ||
} | ||
|
||
protected BaseXmiConditionTransport(Predicate<LicensePack> filter) { | ||
this.filter = filter; | ||
} | ||
|
||
@Override | ||
public ContentType id() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public Collection<Condition> read(InputStream input) throws IOException { | ||
Resource resource = new XMIResourceImpl(); | ||
resource.load(input, | ||
Collections.singletonMap(XMLResource.OPTION_RESOURCE_HANDLER, new LicensesResourceHandler())); | ||
return resource.getContents().stream() // | ||
.filter(LicensePack.class::isInstance) // | ||
.map(LicensePack.class::cast) // | ||
.filter(filter) // | ||
.map(LicensePack::getLicenseGrants) // | ||
.flatMap(i -> StreamSupport.stream(i.spliterator(), false)) // | ||
.map(this::condition) // | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private Condition condition(LicenseGrant descriptor) { | ||
return new BaseCondition(descriptor.getIdentifier(), // | ||
descriptor.getFeatureIdentifier(), // | ||
new BaseVersionMatch(descriptor.getMatchVersion(), // | ||
rule(descriptor.getMatchRule())), // | ||
new BaseValidityPeriodClosed(// | ||
fromDate(descriptor.getValidFrom()), // | ||
fromDate(descriptor.getValidUntil())), // | ||
new BaseEvaluationInstructions(// | ||
new EvaluationType.Of(descriptor.getConditionType()), // | ||
descriptor.getConditionExpression())); | ||
} | ||
|
||
/** | ||
* It looks like default matching rule is not persisted my EMF, this we expect | ||
* {@code null} here | ||
*/ | ||
private MatchingRule rule(String origin) { | ||
if (origin == null) { | ||
return new MatchingRuleDefault(); | ||
} | ||
return new MatchingRuleForIdentifier(origin).get(); | ||
} | ||
|
||
private ZonedDateTime fromDate(Date date) { | ||
if (date == null) { | ||
// it should be in the past to be marked as invalid | ||
return ZonedDateTime.now().minusMinutes(1); | ||
} | ||
return ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...se/passage/lic/internal/licenses/migration/tobemoved/UserFilteringConditionTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* 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.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
public final class UserFilteringConditionTransport extends BaseXmiConditionTransport { | ||
|
||
public UserFilteringConditionTransport(Supplier<String> user) { | ||
super(pack -> user.get().equals(pack.getUserIdentifier())); | ||
Objects.requireNonNull(user, "UserFilteringConditionTransport::user"); //$NON-NLS-1$ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters