-
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 #271 from eclipse-passage/564420-2
Bug 564420 conditions | move HC condition miner to new interfaces
- Loading branch information
Showing
25 changed files
with
775 additions
and
42 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
80 changes: 80 additions & 0 deletions
80
....passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.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,80 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 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.lic.internal.api.conditions; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class ConditionAction { | ||
|
||
private final String name; | ||
|
||
protected ConditionAction(String name) { | ||
Objects.requireNonNull(name, "ConditionAction::name"); //$NON-NLS-1$ | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!ConditionAction.class.isInstance(obj)) { | ||
return false; | ||
} | ||
return name.equals(((ConditionAction) obj).name()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
|
||
public final String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
public static final class Aquire extends ConditionAction { | ||
|
||
public Aquire() { | ||
super("acquire"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Keep extends ConditionAction { | ||
|
||
public Keep() { | ||
super("keep"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Release extends ConditionAction { | ||
|
||
public Release() { | ||
super("release"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Of extends ConditionAction { | ||
|
||
public Of(String name) { | ||
super(name); | ||
} | ||
|
||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
...eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/UserRole.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,80 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 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.lic.internal.api.conditions; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class UserRole { | ||
|
||
private final String role; | ||
|
||
protected UserRole(String role) { | ||
Objects.requireNonNull(role, "UserRole::role"); //$NON-NLS-1$ | ||
this.role = role; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!ConditionAction.class.isInstance(obj)) { | ||
return false; | ||
} | ||
return role.equals(((ConditionAction) obj).name()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return role.hashCode(); | ||
} | ||
|
||
public final String name() { | ||
return role; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return role; | ||
} | ||
|
||
public static final class Admin extends UserRole { | ||
|
||
public Admin() { | ||
super("admin"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Licensee extends UserRole { | ||
|
||
public Licensee() { | ||
super("licensee"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Operator extends UserRole { | ||
|
||
public Operator() { | ||
super("operator"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Of extends UserRole { | ||
|
||
public Of(String role) { | ||
super(role); | ||
} | ||
|
||
} | ||
|
||
} |
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
34 changes: 0 additions & 34 deletions
34
...ge.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/LicensingServerRequest.java
This file was deleted.
Oops, something went wrong.
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
92 changes: 92 additions & 0 deletions
92
...e.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.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,92 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 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.lic.internal.hc.remote.impl; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLEncoder; | ||
import java.util.Arrays; | ||
|
||
import org.eclipse.passage.lic.internal.api.LicensedProduct; | ||
import org.eclipse.passage.lic.internal.api.LicensingException; | ||
import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; | ||
import org.eclipse.passage.lic.internal.api.conditions.UserRole; | ||
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningException; | ||
import org.eclipse.passage.lic.internal.base.NamedData; | ||
import org.eclipse.passage.lic.internal.base.ProductIdentifier; | ||
import org.eclipse.passage.lic.internal.base.ProductVersion; | ||
import org.eclipse.passage.lic.internal.equinox.io.InstallationPath; | ||
import org.eclipse.passage.lic.internal.hc.i18n.HcMessages; | ||
import org.eclipse.passage.lic.internal.hc.remote.Configuration; | ||
import org.eclipse.passage.lic.internal.hc.remote.Request; | ||
import org.eclipse.passage.lic.internal.net.LicensingAction; | ||
import org.eclipse.passage.lic.internal.net.LicensingRole; | ||
import org.eclipse.passage.lic.internal.net.LicensingServerCoordinates; | ||
import org.eclipse.passage.lic.internal.net.LicensingServerCoordinates.HostPort; | ||
|
||
/** | ||
* Basing on | ||
* | ||
* @author user | ||
*/ | ||
@SuppressWarnings("restriction") | ||
final class RemoteConditionsRequest implements Request<HttpURLConnection> { | ||
|
||
private final LicensedProduct product; | ||
|
||
public RemoteConditionsRequest(LicensedProduct product) { | ||
this.product = product; | ||
} | ||
|
||
@Override | ||
public URL url() throws ConditionMiningException { | ||
try { | ||
HostPort corrdinates = new LicensingServerCoordinates(new InstallationPath()).get(); | ||
return new URL("http", //$NON-NLS-1$ | ||
corrdinates.host(), // | ||
Integer.parseInt(corrdinates.port()), // | ||
'?' + parameters()); | ||
} catch (LicensingException // | ||
| NumberFormatException // | ||
| MalformedURLException // | ||
| UnsupportedEncodingException e) { | ||
throw new ConditionMiningException(HcMessages.RemoteConditionsRequest_failed_to_compose_url, e); | ||
} | ||
} | ||
|
||
private String parameters() throws UnsupportedEncodingException { | ||
StringBuilder params = new StringBuilder(); | ||
Arrays.stream(// | ||
new NamedData[] { // | ||
new ProductIdentifier(encode(product.identifier())), // | ||
new ProductVersion(encode(product.version())), // | ||
new LicensingAction(new ConditionAction.Aquire()), // | ||
new LicensingRole(new UserRole.Admin()) }) // | ||
.map(NamedData.Writable<String>::new)// | ||
.forEach(writable -> writable.write(params, "=", "&")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
return params.toString(); | ||
|
||
} | ||
|
||
private String encode(String value) throws UnsupportedEncodingException { | ||
return URLEncoder.encode(value, "UTF-8"); //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
public Configuration<HttpURLConnection> config() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
Oops, something went wrong.