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