|
|
@ -44,17 +44,18 @@ import java.util.Locale;
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public class RegistryBasedLicenseManager implements LicenseManager {
|
|
|
|
public class RegistryBasedLicenseManager implements LicenseManager {
|
|
|
|
|
|
|
|
|
|
|
|
private GenericArtifactManager artifactManager;
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(RegistryBasedLicenseManager.class);
|
|
|
|
private static final Log log = LogFactory.getLog(RegistryBasedLicenseManager.class);
|
|
|
|
|
|
|
|
|
|
|
|
public RegistryBasedLicenseManager() {
|
|
|
|
public RegistryBasedLicenseManager() {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private GenericArtifactManager getArtifactManager() {
|
|
|
|
Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
|
|
|
|
Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
|
|
|
|
if (registry == null) {
|
|
|
|
if (registry == null) {
|
|
|
|
throw new IllegalArgumentException("Registry instance retrieved is null. Hence, " +
|
|
|
|
throw new IllegalArgumentException("Registry instance retrieved is null. Hence, " +
|
|
|
|
"'Registry based license manager cannot be initialized'");
|
|
|
|
"'Registry based license manager cannot be initialized'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.artifactManager = GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
|
|
|
|
return GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
|
|
|
|
} catch (LicenseManagementException e) {
|
|
|
|
} catch (LicenseManagementException e) {
|
|
|
|
throw new IllegalStateException("Failed to initialize generic artifact manager bound to " +
|
|
|
|
throw new IllegalStateException("Failed to initialize generic artifact manager bound to " +
|
|
|
|
"Registry based license manager", e);
|
|
|
|
"Registry based license manager", e);
|
|
|
@ -63,14 +64,17 @@ public class RegistryBasedLicenseManager implements LicenseManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
|
|
|
|
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
|
|
|
|
|
|
|
|
GenericArtifactManager artifactManager = getArtifactManager();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode);
|
|
|
|
GenericArtifact artifact = this.getGenericArtifact(artifactManager, deviceType, languageCode);
|
|
|
|
if (artifact == null) {
|
|
|
|
if (artifact == null) { //Adding a default license
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
License license = new License();
|
|
|
|
log.debug("Generic artifact is null for '" + deviceType + "' device type. Hence license does not " +
|
|
|
|
license.setName(deviceType);
|
|
|
|
"have content");
|
|
|
|
license.setVersion("1.0.0");
|
|
|
|
}
|
|
|
|
license.setLanguage("en_US");
|
|
|
|
return null;
|
|
|
|
license.setText("This is license text");
|
|
|
|
|
|
|
|
addLicense(deviceType, license);
|
|
|
|
|
|
|
|
return license;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.populateLicense(artifact);
|
|
|
|
return this.populateLicense(artifact);
|
|
|
|
} catch (GovernanceException e) {
|
|
|
|
} catch (GovernanceException e) {
|
|
|
@ -104,8 +108,9 @@ public class RegistryBasedLicenseManager implements LicenseManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addLicense(final String deviceType, final License license) throws LicenseManagementException {
|
|
|
|
public void addLicense(final String deviceType, final License license) throws LicenseManagementException {
|
|
|
|
|
|
|
|
GenericArtifactManager artifactManager = getArtifactManager();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage());
|
|
|
|
GenericArtifact artifact = this.getGenericArtifact(artifactManager, deviceType, license.getLanguage());
|
|
|
|
if(artifact != null) {
|
|
|
|
if(artifact != null) {
|
|
|
|
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName());
|
|
|
|
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName());
|
|
|
|
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion());
|
|
|
|
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion());
|
|
|
@ -147,8 +152,8 @@ public class RegistryBasedLicenseManager implements LicenseManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private GenericArtifact getGenericArtifact(final String deviceType, final String languageCode)
|
|
|
|
private GenericArtifact getGenericArtifact(GenericArtifactManager artifactManager, final String deviceType, final
|
|
|
|
throws GovernanceException {
|
|
|
|
String languageCode) throws GovernanceException {
|
|
|
|
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
|
|
|
|
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean matches(GenericArtifact artifact) throws GovernanceException {
|
|
|
|
public boolean matches(GenericArtifact artifact) throws GovernanceException {
|
|
|
|