Skip to content

Commit

Permalink
Merge pull request #1052 from eclipse-passage/1049
Browse files Browse the repository at this point in the history
1049 Operator: issue personal license pack to dedicated folder
  • Loading branch information
eparovyshnaya authored Feb 23, 2022
2 parents 3876f77 + fd9201d commit 827fa26
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
import org.eclipse.passage.lic.base.diagnostic.NoSevereErrors;
import org.eclipse.passage.lic.base.diagnostic.SumOfLists;
import org.eclipse.passage.lic.base.io.FloatingFileExtension;
import org.eclipse.passage.lic.base.io.UserHomeProductResidence;
import org.eclipse.passage.lic.emf.validation.ErrorMessages;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.licenses.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites;
import org.eclipse.passage.lic.licenses.model.api.ProductRef;
import org.eclipse.passage.lic.licenses.model.api.UserGrant;
import org.eclipse.passage.loc.internal.agreements.AgreementRegistry;
Expand Down Expand Up @@ -95,7 +93,7 @@ ServiceInvocationResult<IssuedFloatingLicense> issue(FloatingLicensePack pack,
private ServiceInvocationResult<IssuedFloatingLicense> persistLicenseFiles(FloatingLicensePack pack,
Collection<FloatingLicenseAccess> configs) {
LicensedProduct product = product(pack.getLicense().getProduct());
Path residence = residence(pack.getLicense());
Path residence = new LicensePackResidence(pack.getLicense()).get();
ServiceInvocationResult<List<Path>> license = //
persist(pack, product, residence, decryptedFile(pack), encryptedFile(pack));
BinaryOperator<ServiceInvocationResult<List<Path>>> sum = new BaseServiceInvocationResult.Sum<>(
Expand Down Expand Up @@ -149,14 +147,6 @@ private ServiceInvocationResult<List<Path>> replicateKey(LicensedProduct product
return new BaseServiceInvocationResult<>(Collections.singletonList(key));
}

private Path residence(LicenseRequisites license) {
return new UserHomeProductResidence(//
license.getProduct().getIdentifier(), //
license.getProduct().getVersion())//
.get()//
.resolve(license.getIdentifier());
}

private LicensedProduct product(ProductRef ref) {
return new BaseLicensedProduct(ref.getIdentifier(), ref.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.passage.lic.base.BaseLicensedProduct;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.base.io.PassageFileExtension;
import org.eclipse.passage.lic.base.io.UserHomeProductResidence;
import org.eclipse.passage.lic.emf.validation.ErrorMessages;
import org.eclipse.passage.lic.internal.licenses.model.AssignGrantIdentifiers;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
Expand Down Expand Up @@ -85,8 +84,7 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_error_io, e));
}
LicensedProduct product = product(license);
Path path = new UserHomeProductResidence(product).get();
Path path = new LicensePackResidence(license.getLicense()).get();

Path decrypted;
try {
Expand All @@ -98,7 +96,7 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ

Path encrypted;
try {
encrypted = encrypted(license, product, decrypted);
encrypted = encrypted(license, product(license), decrypted);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_export_error, e));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2022 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.licenses.core;

import java.nio.file.Path;
import java.util.function.Supplier;

import org.eclipse.passage.lic.base.io.UserHomeProductResidence;
import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites;

final class LicensePackResidence implements Supplier<Path> {

private final LicenseRequisites license;

LicensePackResidence(LicenseRequisites license) {
this.license = license;
}

@Override
public Path get() {
return existing(residence());
}

private Path residence() {
return new UserHomeProductResidence(//
license.getProduct().getIdentifier(), //
license.getProduct().getVersion())//
.get()//
.resolve(license.getIdentifier());
}

private Path existing(Path folder) {
folder.toFile().mkdirs();
return folder;
}

}

0 comments on commit 827fa26

Please sign in to comment.