License Management

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

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

@ -17,6 +17,8 @@
*/
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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -35,6 +37,7 @@ import java.util.List;
public class DeviceManagerImpl implements DeviceManager {
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementConfig config;

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

@ -17,21 +17,103 @@
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.apache.commons.logging.Log;
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
public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType,
DeviceManagementConstants.LanguageCodes languageCodes) throws LicenseManagementException {
public License getLicense(final String deviceType,
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);
return null;
}
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");
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.
*
*/
package org.wso2.carbon.device.mgt.core.internal;
import org.apache.commons.logging.Log;
@ -65,7 +64,7 @@ public class LicenseManagementServiceComponent {
*/
protected void setRealmService(RealmService realmService) {
if (log.isDebugEnabled()) {
log.debug("Setting Realm Service");
log.debug("Setting Realm Service in license management");
}
LicenseManagementDataHolder.getInstance().setRealmService(realmService);
}
@ -76,7 +75,7 @@ public class LicenseManagementServiceComponent {
*/
protected void unsetRealmService(RealmService realmService) {
if (log.isDebugEnabled()) {
log.debug("Unsetting Realm Service");
log.debug("Un setting Realm Service in license management");
}
LicenseManagementDataHolder.getInstance().setRealmService(null);
}

@ -20,19 +20,15 @@
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.LicenseManagementException;
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;
public class LicenseManagementService implements LicenseManager{
public class LicenseManagementService implements LicenseManager {
@Override
public License getLicense(DeviceManagementConstants.MobileDeviceTypes deviceType,
DeviceManagementConstants.LanguageCodes languageCode) throws LicenseManagementException {
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
}
}

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

Loading…
Cancel
Save