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

Fix search for FeatureGrant in FloatingLicensePackFromRequest #1094

Closed
Closed
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
Fix search for FeatureGrant in FloatingLicensePackFromRequest
HannesWell committed Oct 27, 2022
commit 2da7e6708b621dad7678710c7d30a866b4aa32ea
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.eclipse.passage.lic.base.conditions.MatchingRuleForIdentifier;
import org.eclipse.passage.lic.internal.base.inspection.hardware.Disk;
import org.eclipse.passage.lic.internal.licenses.model.EmptyFeatureGrant;
import org.eclipse.passage.lic.licenses.FeatureRefDescriptor;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.LicensePlanFeatureDescriptor;
import org.eclipse.passage.lic.licenses.model.api.CompanyRef;
@@ -39,6 +40,7 @@
import org.eclipse.passage.lic.licenses.model.api.ValidityPeriodClosed;
import org.eclipse.passage.lic.licenses.model.api.VersionMatch;
import org.eclipse.passage.lic.licenses.model.meta.LicensesFactory;
import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage;
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.lic.users.UserOriginDescriptor;
import org.eclipse.passage.loc.internal.api.FloatingLicenseRequest;
@@ -187,33 +189,39 @@ private Collection<FeatureGrant> featureGrants(FloatingLicensePack pack) {

private FeatureGrant featureGrant(LicensePlanFeatureDescriptor feature, FloatingLicensePack pack, int no) {
FeatureGrant grant = new EmptyFeatureGrant().get();
String fid = feature.getFeature().getIdentifier();
grant.getFeature().setIdentifier(fid);
grant.getFeature().setIdentifier(feature.getFeature().getIdentifier());
grant.setCapacity(request.defaultCapacity());
grant.setIdentifier(String.format("%s#%d", request.identifier(), no)); //$NON-NLS-1$
grant.setPack(pack);
grant.setValid(featureGrantPeriod(fid));
grant.setVivid(featureGrantVivid(fid));
grant.setValid(featureGrantPeriod(feature.getFeature()));
grant.setVivid(featureGrantVivid(feature.getFeature()));
grant.getFeature().setVersionMatch(version(feature));
return grant;
}

private ValidityPeriod featureGrantPeriod(String feature) {
private ValidityPeriod featureGrantPeriod(FeatureRefDescriptor feature) {
return template//
.flatMap(l -> forFeature(l.getFeatures(), feature)) //
.filter(g -> g.eIsSet(LicensesPackage.eINSTANCE.getFeatureGrant_Vivid())) //
HannesWell marked this conversation as resolved.
Show resolved Hide resolved
.map(g -> EcoreUtil.copy(g.getValid()))//
.orElseGet(this::period);
}

private long featureGrantVivid(String feature) {
private long featureGrantVivid(FeatureRefDescriptor feature) {
return template//
.flatMap(l -> forFeature(l.getFeatures(), feature)) //
.map(FeatureGrant::getVivid)//
.orElse(60L);
}

private Optional<FeatureGrant> forFeature(List<FeatureGrant> all, String feature) {
return all.stream().filter(g -> feature.equals(g.getFeature())).findFirst();
private Optional<FeatureGrant> forFeature(List<FeatureGrant> all, FeatureRefDescriptor feature) {
return all.stream().filter(g -> equals(feature, g.getFeature())).findFirst();
}

private static boolean equals(FeatureRefDescriptor f1, FeatureRefDescriptor f2) {
return f1.getIdentifier().equals(f2.getIdentifier())
HannesWell marked this conversation as resolved.
Show resolved Hide resolved
&& f1.getVersionMatch().getVersion().equals(f2.getVersionMatch().getVersion())
&& f1.getVersionMatch().getRule().equals(f2.getVersionMatch().getRule());
}

private VersionMatch version(LicensePlanFeatureDescriptor feature) {