Added class level and method level comments for Policy core

revert-70aa11f8
mharindu 9 years ago
parent 7fed00a14d
commit 94326323bc

@ -25,34 +25,102 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.List; import java.util.List;
/**
* This interface represents the key operations related to profile features of device policies.
*/
public interface FeatureDAO { public interface FeatureDAO {
/* Feature addFeature(Feature feature) throws FeatureManagerDAOException; /**
* This method is used to add a feature related to given profile.
List<Feature> addFeatures(List<Feature> feature) throws FeatureManagerDAOException; *
* @param feature consists of device specific configurations.
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;*/ * @param profileId id of the profile.
* @return returns ProfileFeature object.
* @throws FeatureManagerDAOException
*/
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) 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; 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 List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException; 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 List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException; FeatureManagerDAOException;
/**
* This method is used to retrieve all the profile features.
*
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> getAllProfileFeatures() 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<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; 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; 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; boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException;
} }

@ -24,20 +24,67 @@ import org.wso2.carbon.policy.mgt.common.Profile;
import java.util.List; import java.util.List;
/**
* This interface represents the key operations related to policy profile.
*/
public interface ProfileDAO { 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; 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; 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; 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; 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; 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; 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); 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 @Override
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
return null; return null;
@ -247,7 +138,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override @Override
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException { public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -258,9 +148,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId()); stmt.setInt(1, profile.getProfileId());
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
} finally { } finally {
@ -270,7 +161,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override @Override
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException { public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -280,9 +170,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
} finally { } finally {
@ -448,7 +339,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override @Override
public boolean deleteFeature(int featureId) throws FeatureManagerDAOException { public boolean deleteFeature(int featureId) throws FeatureManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -459,9 +349,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, featureId); stmt.setInt(1, featureId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); if(stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " + throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " +
"from database.", e); "from database.", e);
@ -471,7 +362,6 @@ public class FeatureDAOImpl implements FeatureDAO {
} }
private Connection getConnection() throws FeatureManagerDAOException { private Connection getConnection() throws FeatureManagerDAOException {
try { try {
return PolicyManagementDAOFactory.getConnection(); return PolicyManagementDAOFactory.getConnection();
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {

@ -133,7 +133,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException { public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -142,9 +141,10 @@ public class ProfileDAOImpl implements ProfileDAO {
String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId()); stmt.setInt(1, profile.getProfileId());
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base."; String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg); log.error(msg);
@ -164,9 +164,10 @@ public class ProfileDAOImpl implements ProfileDAO {
String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base."; String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg); log.error(msg);
@ -178,8 +179,7 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public Profile getProfiles(int profileId) throws ProfileManagerDAOException { public Profile getProfile(int profileId) throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -217,7 +217,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public List<Profile> getAllProfiles() throws ProfileManagerDAOException { public List<Profile> getAllProfiles() throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -259,7 +258,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException { public List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;

@ -397,7 +397,7 @@ public class PolicyManagerImpl implements PolicyManager {
// policyDAO.getTimesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);
// policyDAO.getLocationsOfPolicy(policy); // policyDAO.getLocationsOfPolicy(policy);
profile = profileDAO.getProfiles(profileId); profile = profileDAO.getProfile(profileId);
policy.setProfile(profile); policy.setProfile(profile);
policy.setRoles(roleNames); policy.setRoles(roleNames);
@ -433,7 +433,7 @@ public class PolicyManagerImpl implements PolicyManager {
// policyDAO.getTimesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);
// policyDAO.getLocationsOfPolicy(policy); // policyDAO.getLocationsOfPolicy(policy);
Profile profile = profileDAO.getProfiles(policy.getProfileId()); Profile profile = profileDAO.getProfile(policy.getProfileId());
policy.setProfile(profile); policy.setProfile(profile);
policy.setRoles(roleNames); policy.setRoles(roleNames);

@ -147,7 +147,7 @@ public class ProfileManagerImpl implements ProfileManager {
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
profile = profileDAO.getProfiles(profileId); profile = profileDAO.getProfile(profileId);
featureList = featureDAO.getFeaturesForProfile(profileId); featureList = featureDAO.getFeaturesForProfile(profileId);
deviceType = deviceTypeDAO.getDeviceType(profile.getDeviceType().getId()); deviceType = deviceTypeDAO.getDeviceType(profile.getDeviceType().getId());

Loading…
Cancel
Save