forked from community/device-mgt-core
Merge branch 'master' of https://github.com/manojgunayadev/product-cdm into manojgunayadev-master
commit
5fed717491
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
public class LicenseManagementException extends Exception{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 8606378077242945475L;
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public static long getSerialVersionUID() {
|
||||||
|
return serialVersionUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LicenseManagementException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LicenseManagementException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LicenseManagementException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LicenseManagementException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LicenseManagementException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
* *
|
*
|
||||||
* * WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* * Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* * in compliance with the License.
|
* in compliance with the License.
|
||||||
* * You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
* *
|
*
|
||||||
* * http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* *
|
*
|
||||||
* * Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* * software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* * KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* * specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* * 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.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
|
|
||||||
public class LicenseManager {
|
|
||||||
|
|
||||||
/* public void addLicense(DeviceType deviceType,String langCode, String
|
|
||||||
);*/
|
|
||||||
|
|
||||||
|
public interface LicenseManager {
|
||||||
|
public License getLicense(String deviceType,String languageCodes) throws LicenseManagementException;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.LicenseManager;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||||
|
|
||||||
|
public class LicenseManagementDataHolder {
|
||||||
|
|
||||||
|
private RealmService realmService;
|
||||||
|
private TenantManager tenantManager;
|
||||||
|
private LicenseManager licenseManager;
|
||||||
|
private static LicenseManagementDataHolder thisInstance = new LicenseManagementDataHolder();
|
||||||
|
|
||||||
|
public RealmService getRealmService() {
|
||||||
|
return realmService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRealmService(RealmService realmService) {
|
||||||
|
this.realmService = realmService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TenantManager getTenantManager() {
|
||||||
|
return tenantManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantManager(TenantManager tenantManager) {
|
||||||
|
this.tenantManager = tenantManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LicenseManagementDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LicenseManagementDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
public LicenseManager getLicenseManager() {
|
||||||
|
return licenseManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLicenseManager(LicenseManager licenseManager) {
|
||||||
|
this.licenseManager = licenseManager;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.LicenseManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.LicenseManagerImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.LicenseManagementService;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.license.manager" immediate="true"
|
||||||
|
* @scr.reference name="user.realmservice.default"
|
||||||
|
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setRealmService"
|
||||||
|
* unbind="unsetRealmService"
|
||||||
|
*/
|
||||||
|
public class LicenseManagementServiceComponent {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(LicenseManagementServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing license management core bundle");
|
||||||
|
}
|
||||||
|
LicenseManager licenseManager = new LicenseManagerImpl();
|
||||||
|
LicenseManagementDataHolder.getInstance().setLicenseManager(licenseManager);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Registering OSGi service LicenseManagementService");
|
||||||
|
}
|
||||||
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
|
bundleContext.registerService(LicenseManagementService.class.getName(), new LicenseManagementService(), null);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("License management core bundle has been successfully initialized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Realm Service.
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void setRealmService(RealmService realmService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Setting Realm Service in license management");
|
||||||
|
}
|
||||||
|
LicenseManagementDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsets Realm Service.
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void unsetRealmService(RealmService realmService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Un setting Realm Service in license management");
|
||||||
|
}
|
||||||
|
LicenseManagementDataHolder.getInstance().setRealmService(null);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
|
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.internal.LicenseManagementDataHolder;
|
||||||
|
|
||||||
|
public class LicenseManagementService implements LicenseManager {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
||||||
|
return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue