forked from community/device-mgt-core
commit
6f59913621
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.policy.mgt.common;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
public class PolicyDates {
|
||||
|
||||
private Date startDate; // Start date to apply the policy
|
||||
private Date endDate; // After this date policy will not be applied.
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.policy.mgt.common;
|
||||
|
||||
public class PolicyLocations {
|
||||
|
||||
private String latitude; // Latitude
|
||||
private String longitude; // Longitude
|
||||
|
||||
public String getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(String latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(String longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.policy.mgt.common;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
public class PolicyTimes {
|
||||
|
||||
private int startTime; // Start time to apply the policy.
|
||||
private int endTime; // After this time policy will not be applied
|
||||
|
||||
public int getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(int startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public int getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(int endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.policy.mgt.common;
|
||||
|
||||
public class ProfileManagementException extends Exception {
|
||||
|
||||
private String profileErrorMessage;
|
||||
|
||||
public String getProfileErrorMessage() {
|
||||
return profileErrorMessage;
|
||||
}
|
||||
|
||||
public void setProfileErrorMessage(String profileErrorMessage) {
|
||||
this.profileErrorMessage = profileErrorMessage;
|
||||
}
|
||||
|
||||
public ProfileManagementException(String message) {
|
||||
super(message);
|
||||
setProfileErrorMessage(message);
|
||||
}
|
||||
|
||||
public ProfileManagementException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setProfileErrorMessage(message);
|
||||
}
|
||||
|
||||
public ProfileManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setProfileErrorMessage(message);
|
||||
}
|
||||
|
||||
public ProfileManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProfileManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.mgt;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FeatureManager {
|
||||
|
||||
Feature addFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagementException;
|
||||
|
||||
Feature updateFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
boolean deleteFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException;
|
||||
|
||||
ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException;
|
||||
|
||||
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagementException;
|
||||
|
||||
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagementException;
|
||||
|
||||
List<Feature> getAllFeatures() throws FeatureManagementException;
|
||||
|
||||
List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException;
|
||||
|
||||
List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagementException;
|
||||
|
||||
boolean deleteFeature(int featureId) throws FeatureManagementException;
|
||||
|
||||
boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyManager {
|
||||
|
||||
Policy addPolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy getPolicyByProfileID(int profileId) throws PolicyManagementException;
|
||||
|
||||
Policy getPolicy(int policyId) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPolicies() throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPoliciesOfDeviceType(String deviceType) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPoliciesOfRole(String roleName) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException;
|
||||
|
||||
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.mgt;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProfileManager {
|
||||
|
||||
Profile addProfile(Profile profile) throws ProfileManagementException;
|
||||
|
||||
Profile updateProfile(Profile profile) throws ProfileManagementException;
|
||||
|
||||
boolean deleteProfile(Profile profile) throws ProfileManagementException;
|
||||
|
||||
Profile getProfiles(int profileId) throws ProfileManagementException;
|
||||
|
||||
List<Profile> getAllProfiles() throws ProfileManagementException;
|
||||
|
||||
List<Profile> getProfilesOfDeviceType(String deviceType) throws ProfileManagementException;
|
||||
}
|
@ -0,0 +1,368 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.mgt.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FeatureManagerImpl implements FeatureManager {
|
||||
|
||||
private FeatureDAO featureDAO;
|
||||
private static Log log = LogFactory.getLog(FeatureManagerImpl.class);
|
||||
|
||||
public FeatureManagerImpl() {
|
||||
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature addFeature(Feature feature) throws FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
feature = featureDAO.addFeature(feature);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding feature (" + feature.getName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding feature (" + feature.getName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
features = featureDAO.addFeatures(features);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding feature (" + features.size()+ ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding feature (" + features.size() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature updateFeature(Feature feature) throws FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
feature = featureDAO.updateFeature(feature);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while updating feature (" + feature.getName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while updating feature (" + feature.getName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeature(Feature feature) throws FeatureManagementException {
|
||||
boolean bool;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
bool = featureDAO.deleteFeature(feature.getId());
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while deleting the feature (" + feature.getName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while deleting the feature (" + feature.getName() + ") from database";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
feature = featureDAO.addProfileFeature(feature, profileId);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while adding profile feature (" +
|
||||
feature.getFeature().getName() + " - " + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding profile feature (" +
|
||||
feature.getFeature().getName() + " - " + profileId + ") to database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws
|
||||
FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
feature = featureDAO.updateProfileFeature(feature, profileId);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while updating feature (" +
|
||||
feature.getFeature().getName() + " - " + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while updating feature (" +
|
||||
feature.getFeature().getName() + " - " + profileId + ") in database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
|
||||
FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
features = featureDAO.addProfileFeatures(features, profileId);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding the features to profile id (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while adding the features to profile id (" + profileId + ") to the database";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
|
||||
FeatureManagementException {
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
features = featureDAO.updateProfileFeatures(features, profileId);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while updating the features to profile id (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while updating the features to profile id (" + profileId + ") to the database";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getAllFeatures() throws FeatureManagementException {
|
||||
try {
|
||||
return featureDAO.getAllFeatures();
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the features.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException {
|
||||
try {
|
||||
return featureDAO.getAllFeatures(deviceType);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the features.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagementException {
|
||||
try {
|
||||
return featureDAO.getFeaturesForProfile(profileId);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the features.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeature(int featureId) throws FeatureManagementException {
|
||||
boolean bool;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
bool = featureDAO.deleteFeature(featureId);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while deleting the feature - id (" + featureId + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while deleting the feature - id (" + featureId + ") from database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException {
|
||||
boolean bool;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
bool = featureDAO.deleteFeaturesOfProfile(profile);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while deleting the feature of - profile (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Unable to roll back the transaction");
|
||||
}
|
||||
String msg = "Error occurred while deleting the feature of - profile (" +
|
||||
profile.getProfileName() + ") from database";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
}
|
@ -0,0 +1,568 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.mgt.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyManagerImpl implements PolicyManager {
|
||||
|
||||
private PolicyDAO policyDAO;
|
||||
private ProfileDAO profileDAO;
|
||||
private FeatureDAO featureDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
|
||||
|
||||
public PolicyManagerImpl() {
|
||||
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
||||
this.profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
||||
this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (policy.getProfile() != null && policy.getProfile().getProfileId() == 0) {
|
||||
profileDAO.addProfile(policy.getProfile());
|
||||
featureDAO.addProfileFeatures(policy.getProfile().getProfileFeaturesList(),
|
||||
policy.getProfile().getProfileId());
|
||||
}
|
||||
policy = policyDAO.addPolicy(policy);
|
||||
|
||||
if (policy.getUsers() != null) {
|
||||
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
||||
}
|
||||
|
||||
if (policy.getRoleList() != null) {
|
||||
policyDAO.addPolicyToRole(policy.getRoleList(), policy);
|
||||
}
|
||||
|
||||
if (policy.getDeviceList() != null) {
|
||||
policyDAO.addPolicyToDevice(policy.getDeviceList(), policy);
|
||||
}
|
||||
|
||||
if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
||||
policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy);
|
||||
}
|
||||
|
||||
if (policy.getStartTime() != 0 & policy.getEndTime() != 0) {
|
||||
policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy);
|
||||
}
|
||||
|
||||
if (policy.getLatitude() != null && policy.getLongitude() != null) {
|
||||
policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy);
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the policy (" +
|
||||
policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the profile related to policy (" +
|
||||
policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the features of profile related to policy (" +
|
||||
policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
policy = policyDAO.updatePolicy(policy);
|
||||
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
|
||||
|
||||
if (policy.getUsers() != null) {
|
||||
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
||||
}
|
||||
|
||||
if (policy.getRoleList() != null) {
|
||||
policyDAO.addPolicyToRole(policy.getRoleList(), policy);
|
||||
}
|
||||
|
||||
if (policy.getDeviceList() != null) {
|
||||
policyDAO.addPolicyToDevice(policy.getDeviceList(), policy);
|
||||
}
|
||||
|
||||
if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
||||
policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy);
|
||||
}
|
||||
|
||||
if (policy.getStartTime() != 0 & policy.getEndTime() != 0) {
|
||||
policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy);
|
||||
}
|
||||
|
||||
if (policy.getLatitude() != null && policy.getLongitude() != null) {
|
||||
policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy);
|
||||
}
|
||||
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while updating the policy ("
|
||||
+ policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||
|
||||
boolean bool;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
bool = policyDAO.deletePolicy(policy);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while deleting the policy ("
|
||||
+ policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||
PolicyManagementException {
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (policy.getId() == 0) {
|
||||
policyDAO.addPolicy(policy);
|
||||
}
|
||||
List<Device> deviceList = new ArrayList<Device>();
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
|
||||
deviceList.add(deviceDAO.getDevice(deviceIdentifier));
|
||||
}
|
||||
policy = policyDAO.addPolicyToDevice(deviceList, policy);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
if (policy.getDeviceList() != null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device list of policy is not null.");
|
||||
}
|
||||
policy.getDeviceList().addAll(deviceList);
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device list of policy is null. So added the first device to the list.");
|
||||
}
|
||||
policy.setDeviceList(deviceList);
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the policy ("
|
||||
+ policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the policy to device list";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException {
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (policy.getId() == 0) {
|
||||
policyDAO.addPolicy(policy);
|
||||
}
|
||||
policy = policyDAO.addPolicyToRole(roleNames, policy);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
if (policy.getRoleList() != null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New roles list is added to the policy ");
|
||||
}
|
||||
policy.getRoleList().addAll(roleNames);
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Roles list was null, new roles are added.");
|
||||
}
|
||||
policy.setRoleList(roleNames);
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the policy ("
|
||||
+ policy.getId() + " - " + policy.getPolicyName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagementException {
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (policy.getId() == 0) {
|
||||
policyDAO.addPolicy(policy);
|
||||
}
|
||||
policy = policyDAO.addPolicyToUser(usernameList, policy);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
if (policy.getRoleList() != null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New users list is added to the policy ");
|
||||
}
|
||||
policy.getRoleList().addAll(usernameList);
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Users list was null, new users list is added.");
|
||||
}
|
||||
policy.setRoleList(usernameList);
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the policy ("
|
||||
+ policy.getId() + " - " + policy.getPolicyName() + ") to user list.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyByProfileID(int profileId) throws PolicyManagementException {
|
||||
|
||||
Policy policy;
|
||||
Profile profile;
|
||||
List<Device> deviceList;
|
||||
List<String> roleNames;
|
||||
|
||||
try {
|
||||
policy = policyDAO.getPolicyByProfileID(profileId);
|
||||
deviceList = getPolicyAppliedDevicesIds(policy.getId());
|
||||
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
|
||||
policyDAO.getDatesOfPolicy(policy);
|
||||
policyDAO.getTimesOfPolicy(policy);
|
||||
policyDAO.getLocationsOfPolicy(policy);
|
||||
|
||||
profile = profileDAO.getProfiles(profileId);
|
||||
|
||||
policy.setProfile(profile);
|
||||
policy.setRoleList(roleNames);
|
||||
policy.setDeviceList(deviceList);
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the policy related to profile ID (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the profile related to profile ID (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy(int policyId) throws PolicyManagementException {
|
||||
|
||||
Policy policy;
|
||||
List<Device> deviceList;
|
||||
List<String> roleNames;
|
||||
|
||||
try {
|
||||
policy = policyDAO.getPolicy(policyId);
|
||||
deviceList = getPolicyAppliedDevicesIds(policyId);
|
||||
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
|
||||
policyDAO.getDatesOfPolicy(policy);
|
||||
policyDAO.getTimesOfPolicy(policy);
|
||||
policyDAO.getLocationsOfPolicy(policy);
|
||||
|
||||
Profile profile = profileDAO.getProfiles(policy.getProfile().getProfileId());
|
||||
|
||||
policy.setProfile(profile);
|
||||
policy.setRoleList(roleNames);
|
||||
policy.setDeviceList(deviceList);
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the policy related to policy ID (" + policyId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the profile related to policy ID (" + policyId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPolicies() throws PolicyManagementException {
|
||||
|
||||
List<Policy> policyList;
|
||||
|
||||
try {
|
||||
policyList = policyDAO.getAllPolicies();
|
||||
List<Profile> profileList = profileDAO.getAllProfiles();
|
||||
|
||||
for (Policy policy : policyList) {
|
||||
for (Profile profile : profileList) {
|
||||
if (policy.getProfileId() == profile.getProfileId()) {
|
||||
policy.setProfile(profile);
|
||||
}
|
||||
}
|
||||
policy.setDeviceList(getPolicyAppliedDevicesIds(policy.getId()));
|
||||
policy.setRoleList(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
||||
policyDAO.getDatesOfPolicy(policy);
|
||||
policyDAO.getTimesOfPolicy(policy);
|
||||
policyDAO.getLocationsOfPolicy(policy);
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting all the policies.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting all the profiles.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policyList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
|
||||
List<Integer> policyIdList;
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
try {
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier);
|
||||
policyIdList = policyDAO.getPolicyIdsOfDevice(device);
|
||||
List<Policy> tempPolicyList = policyDAO.getAllPolicies();
|
||||
|
||||
for (Policy policy : tempPolicyList) {
|
||||
for (Integer i : policyIdList) {
|
||||
if (policy.getId() == i) {
|
||||
policies.add(policy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the policies for device identifier (" +
|
||||
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting device related to device identifier (" +
|
||||
deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPoliciesOfDeviceType(String deviceTypeName) throws PolicyManagementException {
|
||||
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
|
||||
try {
|
||||
DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
|
||||
List<Profile> profileList = profileDAO.getProfilesOfDeviceType(deviceType);
|
||||
List<Policy> allPolicies = policyDAO.getAllPolicies();
|
||||
|
||||
for (Profile profile : profileList) {
|
||||
for (Policy policy : allPolicies) {
|
||||
if (policy.getProfileId() == profile.getProfileId()) {
|
||||
policies.add(policy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting all the policies.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting device type object related to (" + deviceTypeName + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPoliciesOfRole(String roleName) throws PolicyManagementException {
|
||||
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
List<Integer> policyIdList;
|
||||
|
||||
try {
|
||||
policyIdList = policyDAO.getPolicyOfRole(roleName);
|
||||
List<Policy> tempPolicyList = policyDAO.getAllPolicies();
|
||||
|
||||
for (Policy policy : tempPolicyList) {
|
||||
for (Integer i : policyIdList) {
|
||||
if (policy.getId() == i) {
|
||||
policies.add(policy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the policies.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException {
|
||||
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
List<Integer> policyIdList;
|
||||
|
||||
try {
|
||||
policyIdList = policyDAO.getPolicyOfUser(username);
|
||||
List<Policy> tempPolicyList = policyDAO.getAllPolicies();
|
||||
|
||||
for (Policy policy : tempPolicyList) {
|
||||
for (Integer i : policyIdList) {
|
||||
if (policy.getId() == i) {
|
||||
policies.add(policy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the policies.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException {
|
||||
|
||||
List<Device> deviceList = new ArrayList<Device>();
|
||||
List<Integer> deviceIdList;
|
||||
|
||||
try {
|
||||
deviceIdList = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
||||
for (Integer integer : deviceIdList) {
|
||||
deviceList.add(deviceDAO.getDevice(integer));
|
||||
}
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the device ids related to policy id (" + policyId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting the devices related to policy id (" + policyId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
}
|
@ -0,0 +1,283 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.mgt.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileManagerImpl implements ProfileManager {
|
||||
|
||||
private static Log log = LogFactory.getLog(ProfileManagerImpl.class);
|
||||
private ProfileDAO profileDAO;
|
||||
private FeatureDAO featureDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
|
||||
public ProfileManagerImpl() {
|
||||
profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
||||
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
||||
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile addProfile(Profile profile) throws ProfileManagementException {
|
||||
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
profile.setCreatedDate(currentTimestamp);
|
||||
profile.setUpdatedDate(currentTimestamp);
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
profile = profileDAO.addProfile(profile);
|
||||
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the profile (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the profile features (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the profile (" + profile.getProfileName() + ") to the database";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile updateProfile(Profile profile) throws ProfileManagementException {
|
||||
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
profile.setUpdatedDate(currentTimestamp);
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
profile = profileDAO.updateProfile(profile);
|
||||
featureDAO.updateProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while updating the profile (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while updating the profile features (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while updating the profile (" + profile.getProfileName() + ") to the database";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteProfile(Profile profile) throws ProfileManagementException {
|
||||
boolean bool = true;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
featureDAO.deleteFeaturesOfProfile(profile);
|
||||
bool = profileDAO.deleteProfile(profile);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while deleting the profile (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while deleting the features from profile (" + profile.getProfileName() + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while deleting the profile (" + profile.getProfileName() + ") from database";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile getProfiles(int profileId) throws ProfileManagementException {
|
||||
Profile profile;
|
||||
List<ProfileFeature> featureList;
|
||||
DeviceType deviceType;
|
||||
|
||||
try {
|
||||
profile = profileDAO.getProfiles(profileId);
|
||||
featureList = featureDAO.getFeaturesForProfile(profileId);
|
||||
deviceType = deviceTypeDAO.getDeviceType(profile.getDeviceType().getId());
|
||||
|
||||
profile.setProfileFeaturesList(featureList);
|
||||
profile.setDeviceType(deviceType);
|
||||
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting profile id (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while getting features related profile id (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting device type related profile id (" + profileId + ")";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Profile> getAllProfiles() throws ProfileManagementException {
|
||||
List<Profile> profileList;
|
||||
try {
|
||||
profileList = profileDAO.getAllProfiles();
|
||||
List<ProfileFeature> featureList = featureDAO.getAllProfileFeatures();
|
||||
List<DeviceType> deviceTypes = deviceTypeDAO.getDeviceTypes();
|
||||
for (Profile profile : profileList) {
|
||||
|
||||
List<ProfileFeature> list = new ArrayList<ProfileFeature>();
|
||||
for (ProfileFeature profileFeature : featureList) {
|
||||
if (profile.getProfileId() == profileFeature.getProfileId()) {
|
||||
list.add(profileFeature);
|
||||
}
|
||||
}
|
||||
profile.setProfileFeaturesList(list);
|
||||
|
||||
for (DeviceType deviceType : deviceTypes) {
|
||||
if (profile.getDeviceType().getId() == deviceType.getId()) {
|
||||
profile.setDeviceType(deviceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting profiles";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while getting features related to profiles";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting device types related to profiles";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
}
|
||||
return profileList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Profile> getProfilesOfDeviceType(String deviceTypeName) throws ProfileManagementException {
|
||||
List<Profile> profileList;
|
||||
List<ProfileFeature> featureList;
|
||||
try {
|
||||
DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
|
||||
profileList = profileDAO.getProfilesOfDeviceType(deviceType);
|
||||
featureList = featureDAO.getAllProfileFeatures();
|
||||
|
||||
for (Profile profile : profileList) {
|
||||
List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>();
|
||||
for (ProfileFeature profileFeature : featureList) {
|
||||
if (profile.getProfileId() == profileFeature.getProfileId()) {
|
||||
profileFeatureList.add(profileFeature);
|
||||
}
|
||||
}
|
||||
profile.setProfileFeaturesList(profileFeatureList);
|
||||
|
||||
}
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while getting profiles";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting device types";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while getting profile features types";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagementException(msg, e);
|
||||
}
|
||||
return profileList;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceCreator {
|
||||
|
||||
private static List<Device> deviceList = new ArrayList<Device>();
|
||||
|
||||
public static List<Device> getDeviceList(DeviceType deviceType) {
|
||||
|
||||
|
||||
Device device = new Device();
|
||||
device.setId(1);
|
||||
device.setDeviceTypeId(1);
|
||||
device.setName("Galaxy S6");
|
||||
device.setOwnerId("geeth");
|
||||
device.setOwnerShip("BYOD");
|
||||
device.setTenantId(-1234);
|
||||
device.setDeviceType(deviceType);
|
||||
device.setStatus(Status.ACTIVE);
|
||||
device.setDeviceIdentificationId("aaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
|
||||
|
||||
Device device2 = new Device();
|
||||
device2.setId(2);
|
||||
device2.setDeviceTypeId(1);
|
||||
device2.setName("Nexus 5");
|
||||
device2.setOwnerId("manoj");
|
||||
device2.setOwnerShip("BYOD");
|
||||
device2.setTenantId(-1234);
|
||||
device2.setDeviceType(deviceType);
|
||||
device.setStatus(Status.ACTIVE);
|
||||
device2.setDeviceIdentificationId("bbbbbbbbbbbbbbbbbbbbbbbb");
|
||||
|
||||
|
||||
deviceList.add(device);
|
||||
// deviceList.add(device2);
|
||||
|
||||
return deviceList;
|
||||
|
||||
}
|
||||
|
||||
public static Device getSingleDevice() {
|
||||
return deviceList.get(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
|
||||
public class DeviceTypeCreator {
|
||||
|
||||
public static DeviceType getDeviceType(){
|
||||
|
||||
DeviceType deviceType = new DeviceType();
|
||||
deviceType.setName("ANDROID");
|
||||
deviceType.setId(1);
|
||||
|
||||
return deviceType;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyCreator {
|
||||
|
||||
public static Policy createPolicy(Profile profile) {
|
||||
Policy policy = new Policy();
|
||||
|
||||
policy.setPolicyName("Test_Policy_01");
|
||||
policy.setGeneric(true);
|
||||
policy.setProfile(profile);
|
||||
List<String> users = new ArrayList<String>();
|
||||
users.add("Dilshan");
|
||||
policy.setUsers(users);
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
|
||||
public static Policy createPolicy2(Profile profile) {
|
||||
Policy policy = new Policy();
|
||||
|
||||
policy.setPolicyName("New test Policy");
|
||||
policy.setGeneric(true);
|
||||
policy.setProfile(profile);
|
||||
policy.setDeviceList(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
|
||||
|
||||
List<String> roles = new ArrayList<String>();
|
||||
roles.add("Role_01");
|
||||
roles.add("Role_02");
|
||||
roles.add("Role_03");
|
||||
|
||||
policy.setRoleList(roles);
|
||||
|
||||
List<String> users = new ArrayList<String>();
|
||||
users.add("Geeth");
|
||||
users.add("Manoj");
|
||||
users.add("Milan");
|
||||
users.add("Dulitha");
|
||||
|
||||
policy.setUsers(users);
|
||||
|
||||
policy.setLatitude("6.927079");
|
||||
policy.setLongitude("79.861243");
|
||||
|
||||
/* DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd ");
|
||||
java.util.Date date = new java.util.Date();
|
||||
|
||||
policy.setStartDate(new java.sql.Timestamp(date.getDate()));*/
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileCreator {
|
||||
|
||||
public static Profile getProfile(List<Feature> features) {
|
||||
Profile profile = new Profile();
|
||||
DeviceType deviceType = new DeviceType();
|
||||
|
||||
deviceType.setId(1);
|
||||
deviceType.setName("ANDROID");
|
||||
|
||||
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
||||
profile.setProfileName("Test Profile");
|
||||
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
profile.setDeviceType(deviceType);
|
||||
|
||||
return profile;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileFeatureCreator {
|
||||
|
||||
public static List<ProfileFeature> getProfileFeature(List<Feature> features) {
|
||||
List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>();
|
||||
|
||||
for (Feature feature : features) {
|
||||
|
||||
ProfileFeature profileFeature = new ProfileFeature();
|
||||
profileFeature.setContent(feature);
|
||||
// profileFeature.setContent("rrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
|
||||
// profileFeature.setProfileId(1);
|
||||
profileFeature.setFeature(feature);
|
||||
profileFeatureList.add(profileFeature);
|
||||
|
||||
}
|
||||
return profileFeatureList;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue