Skip to content

Commit

Permalink
Merge pull request #780 from eclipse-passage/573488
Browse files Browse the repository at this point in the history
Bug 573488 evolve licenses and customers reporting
  • Loading branch information
eparovyshnaya authored May 17, 2021
2 parents 2ae25d7 + 841f751 commit 07d810d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public interface LicenseGrantDescriptor {
* Returns the containing license pack of this license grant.
*
* @return the license pack
* @since 2.0
*/
PersonalLicensePackDescriptor getLicensePack();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 ArSysOp
* Copyright (c) 2018, 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 @@ -12,16 +12,16 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.licenses;

import java.util.Collection;

import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;

/**
*
* @since 0.4.0
*
*/
public interface LicenseRegistry {

Iterable<? extends LicensePlanDescriptor> getLicensePlans();
Collection<? extends LicensePlanDescriptor> getLicensePlans();

LicensePlanDescriptor getLicensePlan(String licensePlanId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -90,7 +91,7 @@ public String resolveIdentifier(LicensePlanDescriptor content) {
}

@Override
public Iterable<LicensePlanDescriptor> getLicensePlans() {
public Collection<LicensePlanDescriptor> getLicensePlans() {
return new ArrayList<>(licensePlanIndex.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<service>
<provide interface="org.eclipse.passage.loc.report.internal.core.user.CustomerStorage"/>
</service>
<reference bind="installLicensesRegistry" interface="org.eclipse.passage.loc.internal.licenses.LicenseRegistry" name="installLicensesRegistry"/>
<reference bind="installUserRegistry" interface="org.eclipse.passage.loc.internal.users.UserRegistry" name="installUserRegistry"/>
<implementation class="org.eclipse.passage.loc.report.internal.core.user.Customers"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
*******************************************************************************/
package org.eclipse.passage.loc.report.internal.core.user;

import java.util.Collections;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.PersonalLicensePackDescriptor;
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.loc.internal.licenses.LicenseRegistry;
import org.eclipse.passage.loc.internal.users.UserRegistry;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand All @@ -38,15 +42,26 @@
public final class Customers implements CustomerStorage {

private UserRegistry users;
private LicenseRegistry licenses;

@Override
public Set<UserDescriptor> forProducts(Set<String> products) {
return Collections.emptySet(); // TODO: fix after LicensePlanDescriptor gains 'personal' licenses
return licenses.getLicensePlans().stream() //
.map(plan -> productLicenses(plan, products))//
.flatMap(Collection::stream)//
.map(this::user)//
.distinct()//
.map(users::getUser)//
.collect(Collectors.toSet());
}

@Override
public Set<String> products() {
return Collections.emptySet(); // TODO:
return licenses.getLicensePlans().stream()//
.map(LicensePlanDescriptor::getPersonal)//
.flatMap(Collection::stream)//
.map(this::product)//
.collect(Collectors.toSet());
}

/**
Expand All @@ -60,4 +75,33 @@ public void installUserRegistry(UserRegistry registry) {
this.users = registry;
}

/**
* It is required to install {@code LIC} {@linkplain LicensesRegistry} as it is
* the source of information provided.
*
* @since 0.1
*/
@Reference
public void installLicensesRegistry(LicenseRegistry registry) {
this.licenses = registry;
}

private Set<PersonalLicensePackDescriptor> productLicenses(LicensePlanDescriptor plan, Set<String> products) {
return plan.getPersonal().stream()//
.filter(lic -> forProduct(lic, products))//
.collect(Collectors.toSet());
}

private boolean forProduct(PersonalLicensePackDescriptor lic, Set<String> products) {
return products.contains(lic.getLicense().getProduct().getIdentifier());
}

private String user(PersonalLicensePackDescriptor pack) {
return pack.getLicense().getUser().getIdentifier();
}

private String product(PersonalLicensePackDescriptor pack) {
return pack.getLicense().getProduct().getIdentifier();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.passage.loc.internal.products.ProductRegistry;
import org.eclipse.passage.loc.report.internal.core.user.CustomerExportService;
import org.eclipse.passage.loc.report.internal.core.user.CustomerStorage;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportCustomersWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.jface.FileForExport;
import org.eclipse.passage.loc.report.internal.ui.jface.TargetPage;
Expand All @@ -43,6 +44,7 @@ public ExportCustomersWizard(ProductRegistry products, CustomerStorage customers
this.preview = new PreviewPage(customers, data);
this.scope = new ScopePage(new Products(products, customers), preview);
this.target = new TargetPage(preview);
setWindowTitle(ExportCustomersWizardMessages.ExposedExportCustomersWizard_dialogTitle);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.passage.loc.internal.products.ProductRegistry;
import org.eclipse.passage.loc.report.internal.core.user.CustomerExportService;
import org.eclipse.passage.loc.report.internal.core.user.CustomerStorage;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportCustomersWizardMessages;
import org.eclipse.swt.widgets.Shell;

/**
Expand All @@ -43,7 +42,6 @@ public void accept(Shell shell) {
shell, //
new ExportCustomersWizard(products, customers, export)//
);
dialog.setTitle(ExportCustomersWizardMessages.ExposedExportCustomersWizard_dialogTitle);
dialog.setPageSize(700, 400);
dialog.open();
}
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 @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.passage.loc.report.internal.core;

import java.util.Collection;
import java.util.List;

import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
Expand All @@ -26,7 +27,7 @@ public FakeLicenseRegistry(List<LicensePlanDescriptor> plans) {
}

@Override
public Iterable<? extends LicensePlanDescriptor> getLicensePlans() {
public Collection<LicensePlanDescriptor> getLicensePlans() {
return plans;
}

Expand Down

0 comments on commit 07d810d

Please sign in to comment.