prabathabey 9 years ago
commit d7e363cef7

@ -53,8 +53,8 @@ public final class DeviceManagementConstants {
throw new AssertionError(); throw new AssertionError();
} }
public final static String LANGUAGE_CODE_ENGLISH_US = "en-us"; 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_UK = "en_UK";
} }
public static final class LicenseProperties { public static final class LicenseProperties {
@ -69,6 +69,7 @@ public final class DeviceManagementConstants {
public static final String VALID_TO = "overview_validityTo"; public static final String VALID_TO = "overview_validityTo";
public static final String TEXT = "overview_license"; public static final String TEXT = "overview_license";
public static final String LICENSE_REGISTRY_KEY = "license"; public static final String LICENSE_REGISTRY_KEY = "license";
public static final String ARTIFACT_NAME = "name";
} }
public static final class NotificationProperties { public static final class NotificationProperties {

@ -71,7 +71,8 @@
org.wso2.carbon.registry.core.exceptions, org.wso2.carbon.registry.core.exceptions,
org.wso2.carbon.registry.core.session, org.wso2.carbon.registry.core.session,
javax.xml.bind, javax.xml.bind,
org.wso2.carbon.utils org.wso2.carbon.utils,
org.apache.commons.logging
</Import-Package> </Import-Package>
</instructions> </instructions>
</configuration> </configuration>

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

@ -19,6 +19,8 @@
package org.wso2.carbon.device.mgt.extensions.license.mgt.registry; package org.wso2.carbon.device.mgt.extensions.license.mgt.registry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
@ -44,6 +46,7 @@ public class RegistryBasedLicenseManager implements LicenseManager {
private Registry registry; private Registry registry;
private GenericArtifactManager artifactManager; private GenericArtifactManager artifactManager;
private static final Log log = LogFactory.getLog(RegistryBasedLicenseManager.class);
public RegistryBasedLicenseManager() { public RegistryBasedLicenseManager() {
Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE); Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
@ -63,21 +66,15 @@ 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 {
try { try {
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() { GenericArtifact artifact = this.getGenericArtifact(deviceType, languageCode);
@Override if (artifact == null) {
public boolean matches(GenericArtifact artifact) throws GovernanceException { if (log.isDebugEnabled()) {
String attributeNameVal = artifact.getAttribute( log.debug("Generic artifact is null for '" + deviceType + "' device type. Hence license does not " +
DeviceManagementConstants.LicenseProperties.NAME); "have content");
String attributeLangVal = artifact.getAttribute(
DeviceManagementConstants.LicenseProperties.LANGUAGE);
return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals
(deviceType) && attributeLangVal.equals(languageCode));
} }
});
if (artifacts == null || artifacts.length <= 0) {
return null; return null;
} }
return this.populateLicense(artifacts[0]); return this.populateLicense(artifact);
} catch (GovernanceException e) { } catch (GovernanceException e) {
throw new LicenseManagementException("Error occurred while retrieving license corresponding to " + throw new LicenseManagementException("Error occurred while retrieving license corresponding to " +
"device type '" + deviceType + "'", e); "device type '" + deviceType + "'", e);
@ -96,26 +93,35 @@ public class RegistryBasedLicenseManager implements LicenseManager {
license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT)); license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT));
DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
license.setValidFrom(format.parse(artifact.getAttribute( String validFrom = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM);
DeviceManagementConstants.LicenseProperties.VALID_FROM))); if (validFrom != null && !validFrom.isEmpty()) {
license.setValidTo(format.parse(artifact.getAttribute( license.setValidFrom(format.parse(validFrom));
DeviceManagementConstants.LicenseProperties.VALID_TO))); }
String validTo = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO);
if (validTo != null && !validTo.isEmpty()) {
license.setValidFrom(format.parse(validTo));
}
return license; return license;
} }
@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 =
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
try { try {
GenericArtifact artifact = GenericArtifact artifact = this.getGenericArtifact(deviceType, license.getLanguage());
artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", if (artifact != null) {
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY)); if (log.isDebugEnabled()) {
log.debug("Generic artifact is null for '" + deviceType + "' device type. Hence license does not " +
"have content");
}
return;
}
artifact = artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", deviceType));
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());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER, license.getProvider()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER, license.getProvider());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE, license.getLanguage()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE, license.getLanguage());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.TEXT, license.getText()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.TEXT, license.getText());
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.ARTIFACT_NAME, license.getName());
Date validTo = license.getValidTo(); Date validTo = license.getValidTo();
if (validTo != null) { if (validTo != null) {
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, validTo.toString());
@ -131,4 +137,20 @@ 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));
}
});
return (artifacts == null || artifacts.length == 0) ? null : artifacts[0];
}
} }

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

@ -923,6 +923,12 @@
<groupId>org.wso2.carbon.commons</groupId> <groupId>org.wso2.carbon.commons</groupId>
<artifactId>org.wso2.carbon.ntask.core</artifactId> <artifactId>org.wso2.carbon.ntask.core</artifactId>
<version>${carbon.commons.version}</version> <version>${carbon.commons.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>

Loading…
Cancel
Save