Fixed 204 issue in LicenseManager

revert-70aa11f8
mharindu 9 years ago
parent cceb3ac5db
commit 8949992148

@ -53,8 +53,8 @@ public final class DeviceManagementConstants {
throw new AssertionError();
}
public final static String LANGUAGE_CODE_ENGLISH_US = "en-us";
public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk";
public final static String LANGUAGE_CODE_ENGLISH_US = "en_US";
public final static String LANGUAGE_CODE_ENGLISH_UK = "en_UK";
}
public static final class LicenseProperties {

@ -46,7 +46,7 @@ public class GenericArtifactManagerFactory {
tenantArtifactManagers.get(tenantId);
if (artifactManager == null) {
/* Hack, to fix https://wso2.org/jira/browse/REGISTRY-2427 */
//GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
artifactManager =
new GenericArtifactManager((org.wso2.carbon.registry.core.Registry) registry,
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY);

@ -63,21 +63,11 @@ public class RegistryBasedLicenseManager implements LicenseManager {
@Override
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
try {
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
@Override
public boolean matches(GenericArtifact artifact) throws GovernanceException {
String attributeNameVal = artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.NAME);
String attributeLangVal = artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.LANGUAGE);
return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals
(deviceType) && attributeLangVal.equals(languageCode));
}
});
if (artifacts == null || artifacts.length <= 0) {
GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode);
if (artifact == null) {
return null;
}
return this.populateLicense(artifacts[0]);
return this.populateLicense(artifact);
} catch (GovernanceException e) {
throw new LicenseManagementException("Error occurred while retrieving license corresponding to " +
"device type '" + deviceType + "'", e);
@ -96,26 +86,35 @@ public class RegistryBasedLicenseManager implements LicenseManager {
license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT));
DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
license.setValidFrom(format.parse(artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.VALID_FROM)));
license.setValidTo(format.parse(artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.VALID_TO)));
String validFrom = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM);
if (validFrom != null && !validFrom.isEmpty()) {
license.setValidFrom(format.parse(validFrom));
}
String validTo = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO);
if (validTo != null && !validTo.isEmpty()) {
license.setValidFrom(format.parse(validTo));
}
return license;
}
@Override
public void addLicense(final String deviceType, final License license) throws LicenseManagementException {
GenericArtifactManager artifactManager =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
try {
GenericArtifact artifact =
artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com",
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY));
GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage());
if (artifact != null) {
return;
}
GenericArtifactManager artifactManager =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
artifact = artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", deviceType));
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER, license.getProvider());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE, license.getLanguage());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.TEXT, license.getText());
artifact.setAttribute("name", license.getName());
// artifact.setId(license.getName());
Date validTo = license.getValidTo();
if (validTo != null) {
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString());
@ -131,4 +130,23 @@ public class RegistryBasedLicenseManager implements LicenseManager {
}
}
private GenericArtifact getGenericArtifact(final String deviceType, final String languageCode)
throws GovernanceException {
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
@Override
public boolean matches(GenericArtifact artifact) throws GovernanceException {
String attributeNameVal = artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.NAME);
String attributeLangVal = artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.LANGUAGE);
return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.
equalsIgnoreCase(deviceType) && attributeLangVal.equalsIgnoreCase(languageCode));
}
});
if (artifacts == null || artifacts.length < 1) {
return null;
}
return artifacts[0];
}
}

@ -6,9 +6,6 @@
<ui>
<list>
<column name="Device Type">
<data type="path" value="overview_provider" href="@{storagePath}"/>
</column>
<column name="Name">
<data type="path" value="overview_name" href="@{storagePath}"/>
</column>
<column name="Language">
@ -21,9 +18,6 @@
</ui>
<content>
<table name="Overview">
<field type="text" required="true">
<name>Provider</name>
</field>
<field type="text" required="true">
<name>Name</name>
</field>

Loading…
Cancel
Save