Skip to content

Commit

Permalink
[OPENENGSB-3845] Fix minor things according to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasseidemann committed Nov 2, 2014
1 parent ac2e1fd commit c7ab667
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion assembly/src/main/filtered-resources/etc/default.global
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
org.openengsb.core.workflow.api.TaskboxService taskbox
org.openengsb.core.workflow.api.TaskboxServiceInternal taskboxinternal
org.openengsb.domain.auditing.AuditingDomain auditing
org.openengsb.core.usersync.SynchronizedUserService syncService
org.openengsb.core.usersync.SynchronizedUserService syncService
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import org.openengsb.domain.userprojects.model.Role;
import org.openengsb.domain.userprojects.model.User;

/**
* A service from this interface should store user-information into one specific data source.
*/
public interface DataSynchronizer {

void checkinUsers(List<User> users) throws SynchronizationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
import org.openengsb.domain.userprojects.model.User;

/**
* This service is responsible to distribute the data to both the
* {@link org.openengsb.core.api.security.service.UserDataManager} and the EKB
* {@link org.openengsb.core.ekb.api.PersistInterface}.
* This service should save the user-information provided for the EngSB to all {@link DataSynchronizer} objects.
*/
public interface SynchronizedUserService {

// Basic user operations methods
void checkinUser(User user);

void checkinUsers(List<User> users);
Expand All @@ -45,7 +42,6 @@ public interface SynchronizedUserService {

void deleteUsersByName(List<String> userNames);

// Basic project operations
void checkinProject(Project project);

void checkinProjects(List<Project> projects);
Expand All @@ -58,7 +54,6 @@ public interface SynchronizedUserService {

void deleteProjectsByName(List<String> projectNames);

// Basic role operations
void checkinRole(Role role);

void checkinRoles(List<Role> roles);
Expand All @@ -71,7 +66,6 @@ public interface SynchronizedUserService {

void deleteRolesByName(List<String> roleNames);

// Basic assignment operations
void checkinAssignment(Assignment assignment);

void checkinAssignments(List<Assignment> assignments);
Expand All @@ -82,7 +76,6 @@ public interface SynchronizedUserService {

void deleteAssignments(List<Assignment> assignments);

// Special Assignment operations
/**
* Deletes all assignments for a specific project.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import org.openengsb.core.api.context.ContextHolder;
import org.openengsb.core.api.model.QueryRequest;
import org.openengsb.core.api.security.AuthenticationContext;
import org.openengsb.core.ekb.api.EKBCommit;
import org.openengsb.core.ekb.api.PersistInterface;
Expand All @@ -36,6 +37,9 @@

import com.google.common.collect.Lists;

/**
* This service implementation stores the given user-data into the EKB via the {@link PersistInterface}.
*/
public class EkbDataSynchronizer implements DataSynchronizer {

private static final Logger LOGGER = LoggerFactory.getLogger(UserManagerDataSynchronizer.class);
Expand All @@ -54,7 +58,7 @@ public void checkinUsers(List<User> users) {
preparePersistenceAccess();

for (User user : users) {
List<User> result = queryService.queryByString(User.class, "username:\"" + user.getUsername() + "\"");
List<User> result = queryService.query(User.class, QueryRequest.query("username", user.getUsername()));

if (result.size() == 0) {
LOGGER.info("Create User " + user.getUsername());
Expand All @@ -63,7 +67,7 @@ public void checkinUsers(List<User> users) {
LOGGER.info("Update User " + user.getUsername());
commit.addUpdate(user);
} else {
LOGGER.error("Error: Duplicate users in EngSB");
LOGGER.warn("Error: Duplicate users in EngSB");
commit.addUpdate(user);
}
}
Expand All @@ -78,7 +82,7 @@ public void deleteUsers(List<User> users) {
preparePersistenceAccess();

for (User user : users) {
List<User> result = queryService.queryByString(User.class, "username:\"" + user.getUsername() + "\"");
List<User> result = queryService.query(User.class, QueryRequest.query("username", user.getUsername()));

if (result.size() == 0) {
LOGGER.warn("User {1} does not exist.", user.getUsername());
Expand Down Expand Up @@ -108,7 +112,7 @@ public void checkinProjects(List<Project> projects) {
preparePersistenceAccess();

for (Project project : projects) {
List<Project> result = queryService.queryByString(Project.class, "name:\"" + project.getName() + "\"");
List<Project> result = queryService.query(Project.class, QueryRequest.query("name", project.getName()));

if (result.size() == 0) {
commit.addInsert(project);
Expand All @@ -127,7 +131,7 @@ public void deleteProjects(List<Project> projects) {
preparePersistenceAccess();

for (Project project : projects) {
List<Project> result = queryService.queryByString(Project.class, "name:\"" + project.getName() + "\"");
List<Project> result = queryService.query(Project.class, QueryRequest.query("name", project.getName()));

if (result.size() == 0) {
LOGGER.warn("Project {1} does not exist.", project.getName());
Expand Down Expand Up @@ -158,7 +162,7 @@ public void checkinRoles(List<Role> roles) {
preparePersistenceAccess();

for (Role role : roles) {
List<Role> result = queryService.queryByString(Role.class, "name:\"" + role.getName() + "\"");
List<Role> result = queryService.query(Role.class, QueryRequest.query("name", role.getName()));

if (result.size() == 0) {
commit.addInsert(role);
Expand All @@ -177,7 +181,7 @@ public void deleteRoles(List<Role> roles) {
preparePersistenceAccess();

for (Role role : roles) {
List<Role> result = queryService.queryByString(Role.class, "name:\"" + role.getName() + "\"");
List<Role> result = queryService.query(Role.class, QueryRequest.query("name", role.getName()));

if (result.size() == 0) {
LOGGER.warn("User {1} does not exist.", role.getName());
Expand Down Expand Up @@ -207,10 +211,10 @@ public void checkinAssignments(List<Assignment> assignments) {
preparePersistenceAccess();

for (Assignment assignment : assignments) {
String query =
"userName:\"" + assignment.getUserName() + "\" and projectName:\"" + assignment.getProjectName()
+ "\"";
List<Assignment> result = queryService.queryByString(Assignment.class, query);
QueryRequest request = QueryRequest.create();
request.addParameter("userName", assignment.getUserName());
request.addParameter("projectName", assignment.getProjectName());
List<Assignment> result = queryService.query(Assignment.class, request);

if (result.size() == 0) {
commit.addInsert(assignment);
Expand Down Expand Up @@ -243,7 +247,7 @@ public void deleteAssignments(List<Assignment> assignments) {
preparePersistenceAccess();

for (Assignment assignment : assignments) {
List<Role> result = queryService.queryByString(Role.class, "uuid:\"" + assignment.getUuid() + "\"");
List<Role> result = queryService.query(Role.class, QueryRequest.query("uuid", assignment.getUuid()));

if (result.size() == 0) {
LOGGER.warn("User {1} does not exist.", assignment.getUuid());
Expand Down Expand Up @@ -309,7 +313,7 @@ private void deleteAssignmentsFromPersistence(List<Assignment> assignments) {
EKBCommit commit = getEKBCommit();

for (Assignment assignment : assignments) {
List<Role> result = queryService.queryByString(Role.class, "uuid:\"" + assignment.getUuid() + "\"");
List<Role> result = queryService.query(Role.class, QueryRequest.query("uuid", assignment.getUuid()));

if (result.size() == 0) {
LOGGER.warn("User {1} does not exist.", assignment.getUuid());
Expand All @@ -323,19 +327,18 @@ private void deleteAssignmentsFromPersistence(List<Assignment> assignments) {
}

private List<Assignment> queryForAssignments(Assignment assignment) {

String query = "";
QueryRequest request = QueryRequest.create();

if (assignment.getUserName() != null && !assignment.getUserName().equals("")) {
query += "userName:\"" + assignment.getUserName() + "\"";
request.addParameter("userName", assignment.getUserName());
}

if (assignment.getProjectName() != null && !assignment.getProjectName().equals("")) {
query += "projectName:\"" + assignment.getProjectName() + "\"";
request.addParameter("projectName", assignment.getProjectName());
}

preparePersistenceAccess();
List<Assignment> result = queryService.queryByString(Assignment.class, query);
List<Assignment> result = queryService.query(Assignment.class, request);
revokePersistenceAccess();

return result;
Expand All @@ -352,7 +355,6 @@ private EKBCommit getEKBCommit() {
}

private void preparePersistenceAccess() {

if (authenticationContext.getAuthenticatedPrincipal() == null
|| !(authenticationContext.getAuthenticatedPrincipal() instanceof String)) {
throw new SynchronizationException("A user with DB access must be logged in.");
Expand All @@ -363,7 +365,6 @@ private void preparePersistenceAccess() {
}

private void revokePersistenceAccess() {

ContextHolder.get().setCurrentContextId(currentContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void deleteAssignment(Assignment assignment) {

@Override
public void deleteAssignment(String userName, String project) {
// TODO Implement me.
deleteAssignments(Lists.newArrayList(new Assignment(userName, project)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This service implementation stores the given user-data into the {@link UserDataManager}.
*/
public class UserManagerDataSynchronizer implements DataSynchronizer {

private static final Logger LOGGER = LoggerFactory.getLogger(UserManagerDataSynchronizer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public String toString() {
return String.format("%s:%s", userName, projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public String toString() {
return String.format("%s", attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import org.openengsb.core.api.model.annotation.OpenEngSBModelId;
import org.openengsb.labs.delegation.service.Provide;

/**
* Note: To make sure that this object can be managed properly by the EDB it is recommended to call the generateUuid
* method after setting all object attributes.
*/
@Provide(context = { Constants.DELEGATION_CONTEXT_MODELS })
@Model
public class Permission {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

import com.google.common.collect.Lists;

/**
* This model contains project information. The field name can be used for the project name, the attributes can be used
* to store additional information.
*/
@Provide(context = { Constants.DELEGATION_CONTEXT_MODELS })
@Model
public class Project {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

import com.google.common.collect.Lists;

/**
* This model contains role information. The field name stores the name of the role, the lists roles and permissions
* should be used to hold references to roles and permissions.
*/
@Provide(context = { Constants.DELEGATION_CONTEXT_MODELS })
@Model
public class Role {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

import com.google.common.collect.Lists;

/**
* This model contains user information. The field username can be used for the users name, the attributes can be used
* to store additional information.
*/
@Provide(context = { Constants.DELEGATION_CONTEXT_MODELS })
@Model
public class User {
Expand Down

0 comments on commit c7ab667

Please sign in to comment.