mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added class level and method level comments for Policy core
This commit is contained in:
parent
7fed00a14d
commit
94326323bc
@ -25,34 +25,102 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This interface represents the key operations related to profile features of device policies.
|
||||
*/
|
||||
public interface FeatureDAO {
|
||||
|
||||
/* Feature addFeature(Feature feature) throws FeatureManagerDAOException;
|
||||
|
||||
List<Feature> addFeatures(List<Feature> feature) throws FeatureManagerDAOException;
|
||||
|
||||
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;*/
|
||||
|
||||
/**
|
||||
* This method is used to add a feature related to given profile.
|
||||
*
|
||||
* @param feature consists of device specific configurations.
|
||||
* @param profileId id of the profile.
|
||||
* @return returns ProfileFeature object.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to update a feature related to given profile.
|
||||
* @param feature consists of device specific configurations.
|
||||
* @param profileId id of the profile.
|
||||
* @return returns updated ProfileFeature object.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to add set of features to a given profile.
|
||||
*
|
||||
* @param features consists of device specific configurations.
|
||||
* @param profileId id of the profile.
|
||||
* @return returns list of ProfileFeature objects.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
|
||||
FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to update set of features to a given profile.
|
||||
*
|
||||
* @param features consists of device specific configurations.
|
||||
* @param profileId id of the profile.
|
||||
* @return returns list of ProfileFeature objects.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
|
||||
FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve all the profile features.
|
||||
*
|
||||
* @return returns list of ProfileFeature objects.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve all the profile features based on device type.
|
||||
*
|
||||
* @return returns list of ProfileFeature objects.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
List<Feature> getAllFeatures(String deviceType) throws FeatureManagerDAOException;
|
||||
|
||||
List<ProfileFeature> getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException;
|
||||
/**
|
||||
* This method is used to retrieve all the profile features of given profile.
|
||||
*
|
||||
* @param profileId id of the profile.
|
||||
* @return returns list of ProfileFeature objects.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used remove a feature.
|
||||
*
|
||||
* @param featureId id of the removing feature.
|
||||
* @return returns true if success.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
boolean deleteFeature(int featureId) throws FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to remove set of features of given profile.
|
||||
*
|
||||
* @param profile that contains features to be removed.
|
||||
* @return returns true if success.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to remove set of features of given profile id.
|
||||
*
|
||||
* @param profileId id of the profile.
|
||||
* @return returns true if success.
|
||||
* @throws FeatureManagerDAOException
|
||||
*/
|
||||
boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException;
|
||||
|
||||
}
|
||||
|
||||
@ -24,20 +24,67 @@ import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This interface represents the key operations related to policy profile.
|
||||
*/
|
||||
public interface ProfileDAO {
|
||||
|
||||
/**
|
||||
* This method is used to add a profile.
|
||||
*
|
||||
* @param profile profile object.
|
||||
* @return returns added profile object.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
Profile addProfile(Profile profile) throws ProfileManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to update a profile
|
||||
* @param profile profile object.
|
||||
* @return returns updated profile object.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
Profile updateProfile(Profile profile) throws ProfileManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to remove a profile.
|
||||
* @param profile profile object
|
||||
* @return returns true if success.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
boolean deleteProfile(Profile profile) throws ProfileManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to remove a profile of given policy id.
|
||||
* @param policyId policy id.
|
||||
* @return returns true if success.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
boolean deleteProfile(int policyId) throws ProfileManagerDAOException;
|
||||
|
||||
Profile getProfiles(int profileId) throws ProfileManagerDAOException;
|
||||
/**
|
||||
* This method is used to retrieve a profile when id is given.
|
||||
* @param profileId profile id.
|
||||
* @return returns profile object.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
Profile getProfile(int profileId) throws ProfileManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve all the profiles.
|
||||
*
|
||||
* @return returns a list of profile objects.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
List<Profile> getAllProfiles() throws ProfileManagerDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve all the profile of given device type.
|
||||
*
|
||||
* @param deviceType device type object.
|
||||
* @return retruns list of profiles.
|
||||
* @throws ProfileManagerDAOException
|
||||
*/
|
||||
List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException;
|
||||
|
||||
}
|
||||
|
||||
@ -43,115 +43,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
|
||||
|
||||
|
||||
/* @Override
|
||||
public Feature addFeature(Feature feature) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
stmt.setString(1, feature.getName());
|
||||
stmt.setString(2, feature.getCode());
|
||||
stmt.setString(3, feature.getDescription());
|
||||
int affectedRows = stmt.executeUpdate();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(affectedRows + " feature is added.");
|
||||
}
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
|
||||
while (generatedKeys.next()) {
|
||||
feature.setId(generatedKeys.getInt(1));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding feature to the database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
||||
}
|
||||
return feature;
|
||||
}*/
|
||||
|
||||
/* @Override
|
||||
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
|
||||
for (Feature feature : features) {
|
||||
stmt.setString(1, feature.getName());
|
||||
stmt.setString(2, feature.getCode());
|
||||
stmt.setString(3, feature.getDescription());
|
||||
stmt.addBatch();
|
||||
}
|
||||
|
||||
int[] affectedRows = stmt.executeBatch();
|
||||
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(affectedRows.length + " features are added to the database.");
|
||||
}
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
int i = 0;
|
||||
|
||||
while (generatedKeys.next()) {
|
||||
features.get(i).setId(generatedKeys.getInt(1));
|
||||
i++;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding feature to the database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
||||
}
|
||||
return featureList;
|
||||
}*/
|
||||
|
||||
|
||||
/* @Override
|
||||
public Feature updateFeature(Feature feature) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ? WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, feature.getName());
|
||||
stmt.setString(2, feature.getCode());
|
||||
stmt.setString(3, feature.getDescription());
|
||||
stmt.setInt(4, feature.getId());
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the
|
||||
database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
|
||||
return feature;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
|
||||
return null;
|
||||
@ -247,7 +138,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
|
||||
@Override
|
||||
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
@ -258,9 +148,10 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profile.getProfileId());
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
|
||||
if (stmt.executeUpdate() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
|
||||
} finally {
|
||||
@ -270,7 +161,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
|
||||
@Override
|
||||
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
@ -280,9 +170,10 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profileId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
|
||||
if (stmt.executeUpdate() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
|
||||
} finally {
|
||||
@ -448,7 +339,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
|
||||
@Override
|
||||
public boolean deleteFeature(int featureId) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
@ -459,9 +349,10 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, featureId);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
|
||||
if(stmt.executeUpdate() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " +
|
||||
"from database.", e);
|
||||
@ -471,7 +362,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
||||
}
|
||||
|
||||
private Connection getConnection() throws FeatureManagerDAOException {
|
||||
|
||||
try {
|
||||
return PolicyManagementDAOFactory.getConnection();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
|
||||
@ -133,7 +133,6 @@ public class ProfileDAOImpl implements ProfileDAO {
|
||||
|
||||
@Override
|
||||
public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
@ -142,9 +141,10 @@ public class ProfileDAOImpl implements ProfileDAO {
|
||||
String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profile.getProfileId());
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
|
||||
if (stmt.executeUpdate() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting the profile from the data base.";
|
||||
log.error(msg);
|
||||
@ -164,9 +164,10 @@ public class ProfileDAOImpl implements ProfileDAO {
|
||||
String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profileId);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
|
||||
if (stmt.executeUpdate() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting the profile from the data base.";
|
||||
log.error(msg);
|
||||
@ -178,8 +179,7 @@ public class ProfileDAOImpl implements ProfileDAO {
|
||||
|
||||
|
||||
@Override
|
||||
public Profile getProfiles(int profileId) throws ProfileManagerDAOException {
|
||||
|
||||
public Profile getProfile(int profileId) throws ProfileManagerDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
@ -217,7 +217,6 @@ public class ProfileDAOImpl implements ProfileDAO {
|
||||
|
||||
@Override
|
||||
public List<Profile> getAllProfiles() throws ProfileManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
@ -259,7 +258,6 @@ public class ProfileDAOImpl implements ProfileDAO {
|
||||
|
||||
@Override
|
||||
public List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
@ -397,7 +397,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
// policyDAO.getTimesOfPolicy(policy);
|
||||
// policyDAO.getLocationsOfPolicy(policy);
|
||||
|
||||
profile = profileDAO.getProfiles(profileId);
|
||||
profile = profileDAO.getProfile(profileId);
|
||||
|
||||
policy.setProfile(profile);
|
||||
policy.setRoles(roleNames);
|
||||
@ -433,7 +433,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
// policyDAO.getTimesOfPolicy(policy);
|
||||
// policyDAO.getLocationsOfPolicy(policy);
|
||||
|
||||
Profile profile = profileDAO.getProfiles(policy.getProfileId());
|
||||
Profile profile = profileDAO.getProfile(policy.getProfileId());
|
||||
|
||||
policy.setProfile(profile);
|
||||
policy.setRoles(roleNames);
|
||||
|
||||
@ -147,7 +147,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.openConnection();
|
||||
profile = profileDAO.getProfiles(profileId);
|
||||
profile = profileDAO.getProfile(profileId);
|
||||
featureList = featureDAO.getFeaturesForProfile(profileId);
|
||||
deviceType = deviceTypeDAO.getDeviceType(profile.getDeviceType().getId());
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user