Skip to content

Commit

Permalink
Merge pull request #872 from eclipse-passage/575166
Browse files Browse the repository at this point in the history
Bug 575166 License Agreement management: license issuing
  • Loading branch information
eparovyshnaya authored Aug 14, 2021
2 parents 4e9ce87 + 1cba969 commit f69bfad
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
import org.eclipse.passage.lic.agreements.model.api.Agreement;
import org.eclipse.passage.lic.api.LicensingException;
import org.eclipse.passage.loc.internal.api.workspace.Agreements;
import org.eclipse.passage.loc.internal.equinox.OperatorGearAware;
import org.eclipse.passage.loc.internal.equinox.AgreementsService;
import org.eclipse.passage.loc.workbench.emfforms.renderers.TextWithButtonRenderer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
Expand Down Expand Up @@ -90,7 +88,7 @@ private String reside(File file) throws Exception {
// rename in already defined name if any:
// String name = definedName().orElse(file.getName());
String name = file.getName();
agreements().located(name).write(Files.readAllBytes(file.toPath()));
new AgreementsService().get().located(name).write(Files.readAllBytes(file.toPath()));
return name;
}

Expand Down Expand Up @@ -127,15 +125,6 @@ private Optional<String> definedName() {
}
}

private Agreements agreements() throws LicensingException {
Optional<Agreements> service = new OperatorGearAware()
.withGear(gear -> Optional.of(gear.workspace().agreements()));
if (!service.isPresent()) {
throw new LicensingException("There is no Agreements service supplied by Operator Workspace"); //$NON-NLS-1$
}
return service.get();
}

private Optional<Agreement> agreement() {
try {
IObservableValue<?> value = getModelValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* 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.loc.internal.equinox;

import java.util.Optional;

import org.eclipse.passage.lic.api.LicensingException;
import org.eclipse.passage.loc.internal.api.workspace.Agreements;

public final class AgreementsService {

public Agreements get() throws LicensingException {
Optional<Agreements> service = new OperatorGearAware()
.withGear(gear -> Optional.of(gear.workspace().agreements()));
if (!service.isPresent()) {
throw new LicensingException("There is no Agreements service supplied by Operator Workspace"); //$NON-NLS-1$
}
return service.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ final class IssuePersonalLicense {
}

ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> template) {
PersonalLicensePack license = adjsut(signed(EcoreUtil.copy(template.get())));
PersonalLicensePack license = new Builder(template.get())//
.adjusted()//
.guarded()//
.withSignature()//
.withAgreements()//
.build();
Optional<String> errors = new ErrorMessages().apply(license);
if (errors.isPresent()) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseValidationFailed(), errors.get()));
Expand All @@ -69,45 +74,86 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_error_io, e));
}
LicensedProduct product = new BaseLicensedProduct(//
license.getLicense().getProduct().getIdentifier(), //
license.getLicense().getProduct().getVersion());
LicensedProduct product = product(license);
Path path = new UserHomeProductResidence(product).get();

Path decrypted;
try {
decrypted = new PersistedDecoded(path, license)//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseDecrypted().get());
events.postEvent(OperatorLicenseEvents.decodedIssued(decrypted.toString()));
decrypted = decrypted(license, path);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_failed_to_save_decoded, e));
}

Path encrypted;
try {
encrypted = new PersistedEncoded(product, decrypted, new ProductPassword(products, operator))//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseEncrypted().get());
encrypted = encrypted(license, product, decrypted);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_export_error, e));
}
events.postEvent(OperatorLicenseEvents.encodedIssued(encrypted.toString()));
return result(license, decrypted, encrypted);
}

private BaseServiceInvocationResult<IssuedLicense> result(PersonalLicensePack license, Path decrypted,
Path encrypted) {
return new BaseServiceInvocationResult<>(new BaseIssuedLicense(license, encrypted, decrypted));
}

private PersonalLicensePack adjsut(PersonalLicensePack license) {
Date issueDate = new Date();
license.getLicense().setIdentifier(UUID.randomUUID().toString());
license.getLicense().setIssueDate(issueDate);
new AssignGrantIdentifiers().accept(license);
new PersonalLicenseIssuingProtection().accept(license);
return license;
private Path encrypted(PersonalLicensePack license, LicensedProduct product, Path decrypted)
throws LicensingException {
Path encrypted = new PersistedEncoded(product, decrypted, new ProductPassword(products, operator))//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseEncrypted().get());
events.postEvent(OperatorLicenseEvents.encodedIssued(encrypted.toString()));
return encrypted;
}

private PersonalLicensePack signed(PersonalLicensePack pack) {
new LicenseSignature().accept(pack.getLicense());
return pack;
private Path decrypted(PersonalLicensePack license, Path path) throws LicensingException {
Path decrypted = new PersistedDecoded(path, license)//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseDecrypted().get());
events.postEvent(OperatorLicenseEvents.decodedIssued(decrypted.toString()));
return decrypted;
}

private BaseLicensedProduct product(PersonalLicensePack license) {
return new BaseLicensedProduct(//
license.getLicense().getProduct().getIdentifier(), //
license.getLicense().getProduct().getVersion());
}

private static final class Builder {

private final PersonalLicensePack pack;

Builder(PersonalLicensePack template) {
this.pack = EcoreUtil.copy(template);
}

Builder withSignature() {
new LicenseSignature().accept(pack.getLicense());
return this;
}

Builder withAgreements() {

// TODO
return this;
}

Builder adjusted() {
pack.getLicense().setIdentifier(UUID.randomUUID().toString());
pack.getLicense().setIssueDate(new Date());
new AssignGrantIdentifiers().accept(pack);
return this;
}

Builder guarded() {
new PersonalLicenseIssuingProtection().accept(pack);
return this;
}

PersonalLicensePack build() {
return pack;
}
}
}

0 comments on commit f69bfad

Please sign in to comment.