-
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.
Merge pull request #878 from eclipse-passage/575166-1
575166 License Agreement management: license issuing
- Loading branch information
Showing
12 changed files
with
185 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
98 changes: 98 additions & 0 deletions
98
...c.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicenseAgreements.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,98 @@ | ||
/******************************************************************************* | ||
* 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.licenses.core; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.passage.lic.agreements.AgreementDescriptor; | ||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.io.Hashes; | ||
import org.eclipse.passage.lic.api.io.HashesRegistry; | ||
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor; | ||
import org.eclipse.passage.lic.licenses.model.api.AgreementData; | ||
import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites; | ||
import org.eclipse.passage.lic.licenses.model.meta.LicensesFactory; | ||
import org.eclipse.passage.loc.internal.agreements.AgreementRegistry; | ||
import org.eclipse.passage.loc.internal.api.workspace.Agreements; | ||
import org.eclipse.passage.loc.internal.equinox.AgreementsService; | ||
import org.eclipse.passage.loc.internal.equinox.OperatorGearAware; | ||
import org.eclipse.passage.loc.internal.licenses.core.i18n.LicensesCoreMessages; | ||
|
||
@SuppressWarnings("restriction") | ||
final class LicenseAgreements { | ||
|
||
private final AgreementRegistry registry; | ||
|
||
LicenseAgreements(AgreementRegistry registry) { | ||
this.registry = registry; | ||
} | ||
|
||
void install(LicensePlanDescriptor plan, LicenseRequisites license) throws LicensingException { | ||
Agreements service = new AgreementsService().get(); // TODO: cashed field | ||
Hashes hashes = hashes();// TODO: cashed field | ||
for (String identifier : plan.getAgreements()) { | ||
installAgreement(license, registry.agreement(identifier), service, hashes); | ||
} | ||
|
||
} | ||
|
||
private void installAgreement(LicenseRequisites license, AgreementDescriptor agreement, Agreements service, | ||
Hashes hashes) throws LicensingException { | ||
if (!service.exists(agreement.getFile())) { | ||
throw new LicensingException(String.format(// | ||
LicensesCoreMessages.LicenseOperatorServiceImpl_failed_to_find_agreement_file, // | ||
service.located(agreement.getFile()).info(), // | ||
agreement.getName())); | ||
} | ||
license.getAgreements().add(data(agreement, service, hashes)); | ||
} | ||
|
||
private AgreementData data(AgreementDescriptor agreement, Agreements service, Hashes hashes) | ||
throws LicensingException { | ||
AgreementData data = LicensesFactory.eINSTANCE.createAgreementData(); | ||
data.setIdentifier(agreement.getIdentifier()); | ||
data.setName(agreement.getName()); | ||
data.setFile(agreement.getFile()); | ||
data.setContentType(agreement.getMime()); | ||
byte[] content = content(agreement, service); | ||
data.setContent(content); | ||
data.setHashAlgo(hashes.id().toString()); | ||
data.setHash(hashes.get(content)); | ||
return data; | ||
} | ||
|
||
private byte[] content(AgreementDescriptor agreement, Agreements service) throws LicensingException { | ||
try { | ||
return service.located(agreement.getFile()).content(); | ||
} catch (Exception e) { | ||
throw new LicensingException(String.format(// | ||
LicensesCoreMessages.LicenseOperatorServiceImpl_failed_to_attach_agreement, // | ||
agreement.getName(), // | ||
service.located(agreement.getFile()).info(), // | ||
e)); | ||
} | ||
} | ||
|
||
private Hashes hashes() throws LicensingException { | ||
Optional<HashesRegistry> service = new OperatorGearAware().withGear(gear -> Optional.of(gear.hashes())); | ||
if (!service.isPresent()) { | ||
throw new LicensingException("There is no HashesRegistry service supplied by Operator Gear"); //$NON-NLS-1$ | ||
} | ||
Collection<Hashes> all = service.get().get().services(); | ||
if (all.isEmpty()) { | ||
throw new LicensingException("There is no Hashes service supplied by Operator Gear"); //$NON-NLS-1$ | ||
} | ||
return all.iterator().next(); | ||
} | ||
} |
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
...core/src/org/eclipse/passage/loc/licenses/trouble/code/LicenseAgreementsAttachFailed.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,24 @@ | ||
/******************************************************************************* | ||
* 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.licenses.trouble.code; | ||
|
||
import org.eclipse.passage.lic.api.diagnostic.TroubleCode; | ||
import org.eclipse.passage.loc.internal.licenses.core.i18n.LicenseTroubleCodeMessages; | ||
|
||
public final class LicenseAgreementsAttachFailed extends TroubleCode { | ||
|
||
public LicenseAgreementsAttachFailed() { | ||
super(903, LicenseTroubleCodeMessages.LicenseAgreementAttachFailed_explanation); | ||
} | ||
|
||
} |
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
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