Merge branch 'manojgunayadev-master'

revert-70aa11f8
Geeth Munasinghe 10 years ago
commit 1ce417f203

@ -43,4 +43,10 @@ public final class DeviceManagementConstants {
public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows"; public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows";
} }
public static final class LanguageCodes{
private LanguageCodes() { throw new AssertionError();}
public final static String LANGUAGE_CODE_ENGLISH_US = "en-us";
public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk";
}
} }

@ -15,7 +15,6 @@
*/ */
package org.wso2.carbon.device.mgt.common; package org.wso2.carbon.device.mgt.common;
@SuppressWarnings("unused")
public class DeviceManagementException extends Exception { public class DeviceManagementException extends Exception {
private static final long serialVersionUID = -3151279311929070297L; private static final long serialVersionUID = -3151279311929070297L;

@ -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;
}
}

@ -121,6 +121,10 @@
<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>
</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;

@ -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;
}
}

@ -50,7 +50,6 @@ import org.wso2.carbon.user.core.service.RealmService;
* bind="setDeviceManagerService" * bind="setDeviceManagerService"
* unbind="unsetDeviceManagerService" * unbind="unsetDeviceManagerService"
*/ */
@SuppressWarnings("unused")
public class DeviceManagementServiceComponent { public class DeviceManagementServiceComponent {
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);

@ -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);
}
}

@ -120,8 +120,11 @@
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId> <artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.governance.api</artifactId>
<version>${carbon.platform.version}</version>
</dependency>
<!--Osgi dependencies--> <!--Osgi dependencies-->
<dependency> <dependency>
<groupId>org.eclipse.osgi</groupId> <groupId>org.eclipse.osgi</groupId>
@ -201,6 +204,7 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

@ -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