License Management

revert-70aa11f8
manoj 10 years ago
parent 87e272a823
commit 0135051d84

@ -121,6 +121,11 @@
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId> <artifactId>org.wso2.carbon.user.api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.governance.api</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -17,6 +17,8 @@
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -35,6 +37,7 @@ import java.util.List;
public class DeviceManagerImpl implements DeviceManager { public class DeviceManagerImpl implements DeviceManager {
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementConfig config; private DeviceManagementConfig config;

@ -21,10 +21,7 @@
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
public interface LicenseManager { public interface LicenseManager {
public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, public License getLicense(String deviceType,String languageCodes) throws LicenseManagementException;
DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException;
} }

@ -17,21 +17,103 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*; import org.apache.commons.logging.Log;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.device.mgt.common.License;
import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.governance.api.exception.GovernanceException;
import org.wso2.carbon.governance.api.generic.GenericArtifactFilter;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.session.UserRegistry;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class LicenseManagerImpl implements LicenseManager{ public class LicenseManagerImpl implements LicenseManager {
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
@Override @Override
public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, public License getLicense(final String deviceType,
DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException { final String languageCodes) throws LicenseManagementException {
if (log.isDebugEnabled()){
log.debug("entered get License in license manager impl");
}
// TODO: After completes JAX-RX user login, this need to be change to CarbonContext
PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("admin");
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(
RegistryType.USER_GOVERNANCE);
GenericArtifact[] filteredArtifacts;
License license = new License();
try {
GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
GenericArtifactManager artifactManager = new GenericArtifactManager(registry, "license");
return null; filteredArtifacts = artifactManager.findGenericArtifacts(
new GenericArtifactFilter() {
public boolean matches(GenericArtifact artifact) throws GovernanceException {
String attributeNameVal = artifact.getAttribute("overview_name");
String attributeLangVal = artifact.getAttribute("overview_language");
return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals
(deviceType) && attributeLangVal.equals(languageCodes));
} }
});
String validFrom;
String validTo;
DateFormat format;
Date fromDate;
Date toDate;
for (GenericArtifact artifact : filteredArtifacts) {
if (log.isDebugEnabled()){
log.debug("Overview name:"+artifact.getAttribute("overview_name"));
log.debug("Overview provider:"+artifact.getAttribute("overview_provider"));
log.debug("Overview Language:"+artifact.getAttribute("overview_language"));
log.debug("overview_validityFrom:"+artifact.getAttribute("overview_validityFrom"));
log.debug("overview_validityTo:"+artifact.getAttribute("overview_validityTo"));
}
validFrom = artifact.getAttribute("overview_validityFrom");
validTo = artifact.getAttribute("overview_validityTo");
format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
try {
fromDate = format.parse(validFrom);
toDate = format.parse(validTo);
if (fromDate.getTime()<= new Date().getTime() && new Date().getTime() <= toDate.getTime()){
license.setLicenseText(artifact.getAttribute("overview_license"));
}
} catch (ParseException e) {
log.error("validFrom:"+ validFrom);
log.error("validTo:"+validTo);
log.error("Valid date parse error:",e);
}
}
} catch (RegistryException regEx) {
log.error("registry exception:",regEx);
throw new LicenseManagementException();
}finally {
PrivilegedCarbonContext.endTenantFlow();
}
return license;
}
} }

@ -16,7 +16,6 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.core.internal; package org.wso2.carbon.device.mgt.core.internal;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -65,7 +64,7 @@ public class LicenseManagementServiceComponent {
*/ */
protected void setRealmService(RealmService realmService) { protected void setRealmService(RealmService realmService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Realm Service"); log.debug("Setting Realm Service in license management");
} }
LicenseManagementDataHolder.getInstance().setRealmService(realmService); LicenseManagementDataHolder.getInstance().setRealmService(realmService);
} }
@ -76,7 +75,7 @@ public class LicenseManagementServiceComponent {
*/ */
protected void unsetRealmService(RealmService realmService) { protected void unsetRealmService(RealmService realmService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Unsetting Realm Service"); log.debug("Un setting Realm Service in license management");
} }
LicenseManagementDataHolder.getInstance().setRealmService(null); LicenseManagementDataHolder.getInstance().setRealmService(null);
} }

@ -20,19 +20,15 @@
package org.wso2.carbon.device.mgt.core.service; package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.License; import org.wso2.carbon.device.mgt.common.License;
import org.wso2.carbon.device.mgt.common.LicenseManagementException; import org.wso2.carbon.device.mgt.common.LicenseManagementException;
import org.wso2.carbon.device.mgt.core.LicenseManager; import org.wso2.carbon.device.mgt.core.LicenseManager;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder;
public class LicenseManagementService implements LicenseManager{ public class LicenseManagementService implements LicenseManager {
@Override @Override
public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType, public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
DeviceManagementConstants.LanguageCodes languageCode) throws LicenseManagementException {
return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
} }
} }

@ -1,16 +1,19 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<artifactType type="application/vnd.wso2-license+xml" shortName="license" singularLabel="License" pluralLabel="Licenses" <artifactType type="application/vnd.wso2-license+xml" shortName="license" singularLabel="License" pluralLabel="Licenses"
hasNamespace="false" iconSet="10"> hasNamespace="false" iconSet="10">
<storagePath>/license/@{overview_provider}/@{overview_name}/@{overview_version}</storagePath> <storagePath>/license/@{overview_provider}/@{overview_name}/@{overview_language}/@{overview_version}</storagePath>
<nameAttribute>overview_name</nameAttribute> <nameAttribute>overview_name</nameAttribute>
<ui> <ui>
<list> <list>
<column name="Provider"> <column name="Device Type">
<data type="path" value="overview_provider" href="@{storagePath}"/> <data type="path" value="overview_provider" href="@{storagePath}"/>
</column> </column>
<column name="Name"> <column name="Name">
<data type="path" value="overview_name" href="@{storagePath}"/> <data type="path" value="overview_name" href="@{storagePath}"/>
</column> </column>
<column name="Language">
<data type="path" value="overview_language" href="@{storagePath}"/>
</column>
<column name="Version"> <column name="Version">
<data type="path" value="overview_version" href="@{storagePath}"/> <data type="path" value="overview_version" href="@{storagePath}"/>
</column> </column>
@ -24,11 +27,17 @@
<field type="text" required="true"> <field type="text" required="true">
<name>Name</name> <name>Name</name>
</field> </field>
<field type="text" required="true">
<name>Language</name>
</field>
<field type="text" required="true"> <field type="text" required="true">
<name>Version</name> <name>Version</name>
</field> </field>
<field type="text"> <field type="text">
<name>Createdtime</name> <name>Validity From</name>
</field>
<field type="text">
<name>Validity To</name>
</field> </field>
<field type="text-area"> <field type="text-area">
<name>License</name> <name>License</name>

Loading…
Cancel
Save