Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
|#739|+Anshul| Audit fields (createdBy, createdDate, modifiedBy, modi…
Browse files Browse the repository at this point in the history
…fiedDate) consistency across all tables.
  • Loading branch information
Sriram Viswanathan committed May 24, 2013
1 parent e622388 commit c713b6d
Show file tree
Hide file tree
Showing 44 changed files with 144 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void updateRole(Role role) {

private void createRoleRights(Role role) {
for (Right right : getRightsWithItsDependents(role.getRights())) {
roleRightsMapper.createRoleRight(role.getId(), right);
roleRightsMapper.createRoleRight(role, right);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
@Repository
public interface RoleRightsMapper {

@Insert("INSERT INTO role_rights(roleId, rightName) VALUES " +
"(#{roleId}, #{right})")
int createRoleRight(@Param(value = "roleId") Long roleId, @Param(value = "right") Right right);
@Insert("INSERT INTO role_rights(roleId, rightName, createdBy) VALUES " +
"(#{role.id}, #{right}, #{role.modifiedBy})")
int createRoleRight(@Param(value = "role") Role role, @Param(value = "right") Right right);

@Select({"SELECT RR.rightName",
"FROM users U, role_assignments RA, role_rights RR WHERE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void shouldSaveRoleWithMappings() throws Exception {
roleRightsRepository.createRole(role);

verify(roleRightsMapper).insertRole(role);
verify(roleRightsMapper).createRoleRight(1L, CONFIGURE_RNR);
verify(roleRightsMapper).createRoleRight(1L, CREATE_REQUISITION);
verify(roleRightsMapper).createRoleRight(role, CONFIGURE_RNR);
verify(roleRightsMapper).createRoleRight(role, CREATE_REQUISITION);
}

@Test
Expand All @@ -74,9 +74,9 @@ public void shouldSaveRoleWithMappingsAndTheirDependentMappings() throws Excepti
roleRightsRepository.createRole(role);

verify(roleRightsMapper).insertRole(role);
verify(roleRightsMapper).createRoleRight(1L, CONFIGURE_RNR);
verify(roleRightsMapper).createRoleRight(1L, CREATE_REQUISITION);
verify(roleRightsMapper, times(1)).createRoleRight(1L, VIEW_REQUISITION);
verify(roleRightsMapper).createRoleRight(role, CONFIGURE_RNR);
verify(roleRightsMapper).createRoleRight(role, CREATE_REQUISITION);
verify(roleRightsMapper, times(1)).createRoleRight(role, VIEW_REQUISITION);
}

@Test
Expand Down Expand Up @@ -129,7 +129,7 @@ public void shouldUpdateRole() {
roleRightsRepository.updateRole(role);
verify(roleRightsMapper).updateRole(role);
verify(roleRightsMapper).deleteAllRightsForRole(100L);
verify(roleRightsMapper).createRoleRight(100L, CONFIGURE_RNR);
verify(roleRightsMapper).createRoleRight(role, CONFIGURE_RNR);
}

@Test
Expand All @@ -141,8 +141,8 @@ public void shouldUpdateRoleAlongWithDependentRights() {

verify(roleRightsMapper).updateRole(role);
verify(roleRightsMapper).deleteAllRightsForRole(100L);
verify(roleRightsMapper).createRoleRight(100L, CREATE_REQUISITION);
verify(roleRightsMapper).createRoleRight(100L, VIEW_REQUISITION);
verify(roleRightsMapper).createRoleRight(role, CREATE_REQUISITION);
verify(roleRightsMapper).createRoleRight(role, VIEW_REQUISITION);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public void shouldGetHomeFacilityIfUserHasRight() throws Exception {
Role r1 = new Role("r1", FALSE, "random description");
roleRightsMapper.insertRole(r1);

roleRightsMapper.createRoleRight(r1.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(r1.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(r1, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(r1, CONFIGURE_RNR);

User user = make(a(defaultUser, with(facilityId, homeFacility.getId())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ public void shouldGetAllProgramsForUserSupervisedFacilitiesForWhichHeHasCreateRn

Role createRnrRole = new Role("R1", FALSE, "Create Requisition");
roleRightsMapper.insertRole(createRnrRole);
roleRightsMapper.createRoleRight(createRnrRole.getId(), Right.CREATE_REQUISITION);
roleRightsMapper.createRoleRight(createRnrRole, Right.CREATE_REQUISITION);
insertRoleAssignments(activeProgramWithCreateRight, user, createRnrRole, supervisoryNode);
insertRoleAssignments(inactiveProgram, user, createRnrRole, supervisoryNode);
insertRoleAssignments(activeProgramForHomeFacility, user, createRnrRole, null);

Role configureRnrRole = new Role("R2", FALSE, "View Rnr Role");
roleRightsMapper.insertRole(configureRnrRole);
roleRightsMapper.createRoleRight(configureRnrRole.getId(), Right.CONFIGURE_RNR);
roleRightsMapper.createRoleRight(configureRnrRole, Right.CONFIGURE_RNR);
insertRoleAssignments(activeProgramWithConfigureRight, user, configureRnrRole, supervisoryNode);

List<Program> programs = programMapper.getUserSupervisedActivePrograms(user.getId(), "{CREATE_REQUISITION, CONFIGURE_RNR}");
Expand All @@ -158,11 +158,11 @@ public void shouldFetchActiveProgramsSupportedByAFacilityForAUserWithRight() {

Role r1 = new Role("r1", FALSE, "random description");
roleRightsMapper.insertRole(r1);
roleRightsMapper.createRoleRight(r1.getId(), Right.CREATE_REQUISITION);
roleRightsMapper.createRoleRight(r1, Right.CREATE_REQUISITION);

Role r2 = new Role("r2", FALSE, "authorize role");
roleRightsMapper.insertRole(r2);
roleRightsMapper.createRoleRight(r2.getId(), Right.AUTHORIZE_REQUISITION);
roleRightsMapper.createRoleRight(r2, Right.AUTHORIZE_REQUISITION);

insertRoleAssignments(activeProgram, user, r1, null);
insertRoleAssignments(anotherActiveProgram, user, r2, null);
Expand Down Expand Up @@ -192,7 +192,7 @@ public void shouldGetActiveProgramsForUserWithGivenRights() throws Exception {

Role r1 = new Role("r1", FALSE, "random description");
roleRightsMapper.insertRole(r1);
roleRightsMapper.createRoleRight(r1.getId(), Right.APPROVE_REQUISITION);
roleRightsMapper.createRoleRight(r1, Right.APPROVE_REQUISITION);

insertRoleAssignments(activeProgram, user, r1, null);
insertRoleAssignments(inactiveProgram, user, r1, null);
Expand Down Expand Up @@ -225,7 +225,7 @@ public void shouldGetProgramsForAUserByFacilityAndRights() throws Exception {

Role r1 = new Role("r1", FALSE, "random description");
roleRightsMapper.insertRole(r1);
roleRightsMapper.createRoleRight(r1.getId(), Right.VIEW_REQUISITION);
roleRightsMapper.createRoleRight(r1, Right.VIEW_REQUISITION);

insertRoleAssignments(activeProgram, user, r1, null);
insertRoleAssignments(inactiveProgram, user, r1, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public void shouldReturnProgramAvailableForAFacilityForAUserWithGivenRights() th
Role r2 = new Role("r2", FALSE, "random description");
roleRightsMapper.insertRole(r2);

roleRightsMapper.createRoleRight(r1.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(r1.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(r2.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(r1, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(r1, CONFIGURE_RNR);
roleRightsMapper.createRoleRight(r2, CONFIGURE_RNR);

SupervisoryNode supervisoryNode = make(a(SupervisoryNodeBuilder.defaultSupervisoryNode));
supervisoryNode.setFacility(facility);
Expand Down Expand Up @@ -154,7 +154,7 @@ public void shouldGetHomeFacilityRolesForAUserOnAGivenProgramWithRights() throws
roleRightsMapper.insertRole(r1);
Role r2 = new Role("r2", FALSE, "random description");
roleRightsMapper.insertRole(r2);
roleRightsMapper.createRoleRight(r2.getId(), Right.CREATE_REQUISITION);
roleRightsMapper.createRoleRight(r2, Right.CREATE_REQUISITION);

SupervisoryNode supervisoryNode = make(a(SupervisoryNodeBuilder.defaultSupervisoryNode));
supervisoryNode.setFacility(facility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void shouldGetAllRightsForAUserByUserName() throws Exception {

insertRoleAssignments(program, user, role);

roleRightsMapper.createRoleRight(role.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(role, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role, CONFIGURE_RNR);

allRightsForUser = roleRightsMapper.getAllRightsForUserByUserName(user.getUserName());
assertThat(allRightsForUser.size(), is(2));
Expand All @@ -102,8 +102,8 @@ public void shouldGetAllRightsForAUserByUserId() throws Exception {

insertRoleAssignments(program, user, role);

roleRightsMapper.createRoleRight(role.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(role, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role, CONFIGURE_RNR);

allRightsForUser = roleRightsMapper.getAllRightsForUserById(user.getId());
assertThat(allRightsForUser.size(), is(2));
Expand All @@ -114,8 +114,8 @@ public void shouldGetRoleAndRights() throws Exception {
Role role = new Role(111L, "role name", Boolean.FALSE, "description", null);
roleRightsMapper.insertRole(role);

roleRightsMapper.createRoleRight(role.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role.getId(), MANAGE_FACILITY);
roleRightsMapper.createRoleRight(role, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role, MANAGE_FACILITY);

Role resultRole = roleRightsMapper.getRole(role.getId());

Expand All @@ -141,8 +141,8 @@ public void shouldThrowDuplicateKeyExceptionIfDuplicateRoleName() throws Excepti
public void shouldReturnAllRolesInSystem() throws Exception {
Role role = new Role("role name", FALSE, "");
roleRightsMapper.insertRole(role);
roleRightsMapper.createRoleRight(role.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(role.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role, CONFIGURE_RNR);
roleRightsMapper.createRoleRight(role, CREATE_REQUISITION);

List<Role> roles = new ArrayList();
roles.addAll(roleRightsMapper.getAllRoles());
Expand Down Expand Up @@ -178,8 +178,8 @@ public void shouldUpdateRole() {
public void shouldDeleteRights() throws Exception {
Role role = new Role(11L, "Right Name", Boolean.FALSE, "Right Desc", null);
roleRightsMapper.insertRole(role);
roleRightsMapper.createRoleRight(role.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role.getId(), UPLOADS);
roleRightsMapper.createRoleRight(role, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role, UPLOADS);

assertThat(roleRightsMapper.deleteAllRightsForRole(role.getId()), is(2));
}
Expand All @@ -199,10 +199,10 @@ public void shouldGetRightsForAUserOnSupervisoryNodeAndProgram() throws Exceptio


Role role1 = insertRole("r1", "random description");
roleRightsMapper.createRoleRight(role1.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role1, CREATE_REQUISITION);
Role role2 = insertRole("r2", "random description");
roleRightsMapper.createRoleRight(role2.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role2.getId(), AUTHORIZE_REQUISITION);
roleRightsMapper.createRoleRight(role2, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role2, AUTHORIZE_REQUISITION);

roleAssignmentMapper.insertRoleAssignment(user.getId(), program.getId(), supervisoryNode1.getId(), role1.getId());
roleAssignmentMapper.insertRoleAssignment(user.getId(), program.getId(), supervisoryNode2.getId(), role2.getId());
Expand All @@ -220,10 +220,10 @@ public void shouldGetRightsForAUserOnHomeFacilityAndProgram() throws Exception {
Program program = insertProgram(make(a(defaultProgram, with(programCode, "p1"))));

Role role1 = insertRole("r1", "random description");
roleRightsMapper.createRoleRight(role1.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role1, CREATE_REQUISITION);
Role role2 = insertRole("r2", "random description");
roleRightsMapper.createRoleRight(role2.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role2.getId(), AUTHORIZE_REQUISITION);
roleRightsMapper.createRoleRight(role2, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(role2, AUTHORIZE_REQUISITION);

roleAssignmentMapper.insertRoleAssignment(user.getId(), program.getId(), null, role1.getId());
roleAssignmentMapper.insertRoleAssignment(user.getId(), program.getId(), null, role2.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public void shouldGetAllSupervisoryNodesInTheHierarchyForAUserAndProgramWithAppr
Role configureRnrRole = new Role("configure rnr", FALSE, "random description");
roleRightsMapper.insertRole(configureRnrRole);

roleRightsMapper.createRoleRight(createRole.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(configureRnrRole.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(createRole, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(configureRnrRole, CONFIGURE_RNR);

supervisoryNodeMapper.insert(supervisoryNode);

Expand Down Expand Up @@ -177,8 +177,8 @@ public void shouldGetAllSupervisoryNodesInTheHierarchyForAUserWithAppropriateRig
Role configureRnrRole = new Role("configure rnr", FALSE, "random description");
roleRightsMapper.insertRole(configureRnrRole);

roleRightsMapper.createRoleRight(createRole.getId(), CREATE_REQUISITION);
roleRightsMapper.createRoleRight(configureRnrRole.getId(), CONFIGURE_RNR);
roleRightsMapper.createRoleRight(createRole, CREATE_REQUISITION);
roleRightsMapper.createRoleRight(configureRnrRole, CONFIGURE_RNR);

supervisoryNodeMapper.insert(supervisoryNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void shouldGetUsersWithGivenRightInNodeForProgram() {
Program program = insertProgram(make(a(defaultProgram, with(programCode, "p1"))));

Role role = insertRole();
roleRightsMapper.createRoleRight(role.getId(), APPROVE_REQUISITION);
roleRightsMapper.createRoleRight(role, APPROVE_REQUISITION);

roleAssignmentMapper.insertRoleAssignment(someUser.getId(), program.getId(), supervisoryNode.getId(), role.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ CREATE TABLE facilities (
goDownDate DATE,
comment TEXT,
dataReportable BOOLEAN,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX i_facility_name ON facilities(name);
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ CREATE TABLE programs_supported (
programId INTEGER REFERENCES programs (id),
startDate TIMESTAMP,
active BOOLEAN NOT NULL,
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (facilityId, programId)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ CREATE TABLE program_product_price_history (
source VARCHAR(50),
startDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
endDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX i_program_product_price_history_programProductId ON program_product_price_history(programProductId);
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ CREATE TABLE program_products (
dosesPerMonth INTEGER NOT NULL,
active BOOLEAN NOT NULL,
currentPrice NUMERIC(20,2) DEFAULT 0,
modifiedBy INTEGER,
modifiedDate TIMESTAMP,
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT NOW(),
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (productId, programId)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ CREATE TABLE processing_periods (
startDate TIMESTAMP NOT NULL,
endDate TIMESTAMP NOT NULL,
numberOfMonths INTEGER,
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE UNIQUE INDEX uc_processing_period_name_scheduleId ON processing_periods(LOWER(name), scheduleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CREATE TABLE processing_schedules (
code VARCHAR(50) UNIQUE NOT NULL,
name VARCHAR(50) NOT NULL,
description VARCHAR(250),
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT NOW(),
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT NOW()
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ CREATE TABLE facility_approved_products (
facilityTypeId INTEGER REFERENCES facility_types(id) NOT NULL,
programProductId INTEGER REFERENCES program_products(id) NOT NULL,
maxMonthsOfStock INTEGER NOT NULL,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT NOW(),
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT NOW(),
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (facilityTypeId, programProductId)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CREATE TABLE roles (
adminRole BOOLEAN NOT NULL,
name VARCHAR(50) NOT NULL UNIQUE,
description VARCHAR(250),
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT NOW(),
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT NOW()
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedBy INTEGER,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
CREATE TABLE rights (
name VARCHAR(200) PRIMARY KEY,
adminRight BOOLEAN NOT NULL,
description VARCHAR(200)
description VARCHAR(200),
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
CREATE TABLE role_rights (
roleId INT REFERENCES roles(id) NOT NULL,
rightName VARCHAR REFERENCES rights(name) NOT NULL,
CONSTRAINT unique_role_right UNIQUE (roleId, rightName)
CONSTRAINT unique_role_right UNIQUE (roleId, rightName),
createdBy INTEGER,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Loading

0 comments on commit c713b6d

Please sign in to comment.