diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java index 0613f4e50292cfa87e96343f604c8ea6c7a250b3..ea272d3b20a9da8e083e505f90883aa55ee06358 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java @@ -49,7 +49,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.NewRoleAssignment; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; -import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; @@ -59,8 +58,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; -import ch.systemsx.cisd.openbis.plugin.ISampleServerPlugin; -import ch.systemsx.cisd.openbis.plugin.SampleServerPluginRegistry; /** * Implementation of client-server interface. @@ -284,18 +281,6 @@ public final class CommonServer extends AbstractServer<ICommonServer> implements return sampleTable.getSamples(); } - public final SampleGenerationDTO getSampleInfo(final String sessionToken, - final SampleIdentifier identifier) - { - final Session session = getSessionManager().getSession(sessionToken); - final ISampleBO sampleBO = getBusinessObjectFactory().createSampleBO(session); - sampleBO.loadBySampleIdentifier(identifier); - final SamplePE sample = sampleBO.getSample(); - final ISampleServerPlugin plugin = - SampleServerPluginRegistry.getPlugin(this, sample.getSampleType()); - return plugin.getSlaveServer().getSampleInfo(getDAOFactory(), session, sample); - } - public final List<ExternalDataPE> listExternalData(final String sessionToken, final SampleIdentifier identifier) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java index be92ad5fa2dff870a5d3a04cd50d61998c8e7f2d..29161b052c72ec7062d9189f8a28c2c4ccede3c1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java @@ -174,7 +174,7 @@ final class CommonServerLogger extends AbstractServerLogger implements ICommonSe return null; } - public void registerSample(String sessionToken, SampleToRegisterDTO newSample) + public void registerSample(final String sessionToken, final SampleToRegisterDTO newSample) { logTracking(sessionToken, "register_sample", "SAMPLE_TYPE(%s) SAMPLE(%S)", newSample .getSampleTypeCode(), newSample.getSampleIdentifier()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java index c33a8733c0f45f6faeb21ba35753fd30bc34a045..c10ab3bbd6ce91b3aefff320b8a8ce14179ae213 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ICommonServer.java @@ -25,7 +25,6 @@ import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.ReturnVa import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed; import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.GroupIdentifierPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleToRegisterDTOPredicate; import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.GroupValidator; import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.MatchingEntityValidator; import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; @@ -34,9 +33,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ListSampleCriteriaDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; -import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SearchHit; import ch.systemsx.cisd.openbis.generic.shared.dto.SearchableEntity; @@ -135,14 +132,6 @@ public interface ICommonServer extends IServer public List<SamplePE> listSamples(final String sessionToken, final ListSampleCriteriaDTO criteria); - /** - * For given {@link SampleIdentifier} returns the corresponding {@link SamplePE}. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - public SampleGenerationDTO getSampleInfo(final String sessionToken, - final SampleIdentifier identifier); - /** * For given {@link SampleIdentifier} returns the corresponding list of {@link ExternalDataPE}. */ @@ -160,13 +149,4 @@ public interface ICommonServer extends IServer public List<SearchHit> listMatchingEntities(final String sessionToken, final SearchableEntity[] searchableEntities, final String queryText); - /** - * Registers a new sample. - */ - @Transactional - @RolesAllowed(RoleSet.USER) - public void registerSample(final String sessionToken, - @AuthorizationGuard(guardClass = SampleToRegisterDTOPredicate.class) - final SampleToRegisterDTO newSample); - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java index b6f7f2ead535f4a077bffe344b4f22358792f789..c328c276dd66140d561d86e44d3c69956d77fb94 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java @@ -16,49 +16,18 @@ package ch.systemsx.cisd.openbis.plugin.generic.server; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.annotation.Resource; - -import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Component; -import ch.systemsx.cisd.authentication.IAuthenticationService; import ch.systemsx.cisd.authentication.ISessionManager; -import ch.systemsx.cisd.authentication.Principal; -import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; -import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.utilities.ParameterChecker; import ch.systemsx.cisd.openbis.generic.server.AbstractServer; -import ch.systemsx.cisd.openbis.generic.server.ComponentNames; -import ch.systemsx.cisd.openbis.generic.server.business.bo.IExternalDataTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.IGenericBusinessObjectFactory; -import ch.systemsx.cisd.openbis.generic.server.business.bo.IGroupBO; -import ch.systemsx.cisd.openbis.generic.server.business.bo.IRoleAssignmentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; -import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleTable; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; -import ch.systemsx.cisd.openbis.generic.server.dataaccess.IRoleAssignmentDAO; -import ch.systemsx.cisd.openbis.generic.server.util.GroupIdentifierHelper; -import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.ListSampleCriteriaDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.NewRoleAssignment; -import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SearchHit; -import ch.systemsx.cisd.openbis.generic.shared.dto.SearchableEntity; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.plugin.ISampleServerPlugin; import ch.systemsx.cisd.openbis.plugin.SampleServerPluginRegistry; @@ -74,19 +43,14 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.ResourceNames; public final class GenericServer extends AbstractServer<IGenericServer> implements ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer { - @Resource(name = ComponentNames.AUTHENTICATION_SERVICE) - private IAuthenticationService authenticationService; - public GenericServer() { } - GenericServer(final IAuthenticationService authenticationService, - final ISessionManager<Session> sessionManager, final IDAOFactory daoFactory, + GenericServer(final ISessionManager<Session> sessionManager, final IDAOFactory daoFactory, final IGenericBusinessObjectFactory boFactory) { super(sessionManager, daoFactory, boFactory); - this.authenticationService = authenticationService; } // @@ -115,179 +79,6 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen // IGenericServer // - public final List<GroupPE> listGroups(final String sessionToken, - final DatabaseInstanceIdentifier identifier) - { - final Session session = getSessionManager().getSession(sessionToken); - final DatabaseInstancePE databaseInstance = - GroupIdentifierHelper.getDatabaseInstance(identifier, getDAOFactory()); - final List<GroupPE> groups = getDAOFactory().getGroupDAO().listGroups(databaseInstance); - final Long homeGroupID = session.tryGetHomeGroupId(); - for (final GroupPE group : groups) - { - group.setHome(homeGroupID != null && homeGroupID.equals(group.getId())); - } - Collections.sort(groups); - return groups; - } - - public final void registerGroup(final String sessionToken, final String groupCode, - final String descriptionOrNull, final String groupLeaderOrNull) - { - final Session session = getSessionManager().getSession(sessionToken); - final IGroupBO groupBO = getBusinessObjectFactory().createGroupBO(session); - groupBO.define(groupCode, descriptionOrNull, groupLeaderOrNull); - groupBO.save(); - } - - public final void registerPerson(final String sessionToken, final String userID) - { - final Session session = getSessionManager().getSession(sessionToken); - final PersonPE person = getDAOFactory().getPersonDAO().tryFindPersonByUserId(userID); - if (person != null) - { - throw UserFailureException.fromTemplate("Person '%s' already exists.", userID); - } - final String applicationToken = authenticationService.authenticateApplication(); - if (applicationToken == null) - { - throw new EnvironmentFailureException("Authentication service cannot be accessed."); - } - try - { - final Principal principal = - authenticationService.getPrincipal(applicationToken, userID); - createPerson(principal, session.tryGetPerson()); - } catch (final IllegalArgumentException e) - { - throw new UserFailureException("Person '" + userID - + "' unknown by the authentication service."); - } - } - - public final List<RoleAssignmentPE> listRoles(final String sessionToken) - { - getSessionManager().getSession(sessionToken); - return getDAOFactory().getRoleAssignmentDAO().listRoleAssignments(); - } - - public final void registerGroupRole(final String sessionToken, final RoleCode roleCode, - final GroupIdentifier groupIdentifier, final String person) - { - final Session session = getSessionManager().getSession(sessionToken); - - final NewRoleAssignment newRoleAssignment = new NewRoleAssignment(); - newRoleAssignment.setUserId(person); - newRoleAssignment.setGroupIdentifier(groupIdentifier); - newRoleAssignment.setRole(roleCode); - - final IRoleAssignmentTable table = - getBusinessObjectFactory().createRoleAssignmentTable(session); - table.add(newRoleAssignment); - table.save(); - - } - - public final void registerInstanceRole(final String sessionToken, final RoleCode roleCode, - final String person) - { - final Session session = getSessionManager().getSession(sessionToken); - - final NewRoleAssignment newRoleAssignment = new NewRoleAssignment(); - newRoleAssignment.setUserId(person); - newRoleAssignment.setDatabaseInstanceIdentifier(new DatabaseInstanceIdentifier( - DatabaseInstanceIdentifier.HOME)); - newRoleAssignment.setRole(roleCode); - - final IRoleAssignmentTable table = - getBusinessObjectFactory().createRoleAssignmentTable(session); - table.add(newRoleAssignment); - table.save(); - - } - - public final void deleteGroupRole(final String sessionToken, final RoleCode roleCode, - final GroupIdentifier groupIdentifier, final String person) - { - final Session session = getSessionManager().getSession(sessionToken); - - final RoleAssignmentPE roleAssignment = - getDAOFactory().getRoleAssignmentDAO().tryFindGroupRoleAssignment(roleCode, - groupIdentifier.getGroupCode(), person); - if (roleAssignment == null) - { - throw new UserFailureException("Given group role does not exist."); - } - final PersonPE personPE = session.tryGetPerson(); - if (roleAssignment.getPerson().equals(personPE) - && roleAssignment.getRole().equals(RoleCode.ADMIN)) - { - boolean isInstanceAdmin = false; - for (final RoleAssignmentPE roleAssigment : personPE.getRoleAssignments()) - { - if (roleAssigment.getDatabaseInstance() != null - && roleAssigment.getRole().equals(RoleCode.ADMIN)) - { - isInstanceAdmin = true; - } - } - if (isInstanceAdmin == false) - { - throw new UserFailureException( - "For safety reason you cannot give away your own group admin power. " - + "Ask instance admin to do that for you."); - } - } - getDAOFactory().getRoleAssignmentDAO().deleteRoleAssignment(roleAssignment); - } - - public final void deleteInstanceRole(final String sessionToken, final RoleCode roleCode, - final String person) - { - final Session session = getSessionManager().getSession(sessionToken); - final IRoleAssignmentDAO roleAssignmentDAO = getDAOFactory().getRoleAssignmentDAO(); - final RoleAssignmentPE roleAssignment = - roleAssignmentDAO.tryFindInstanceRoleAssignment(roleCode, person); - if (roleAssignment == null) - { - throw new UserFailureException("Given database instance role does not exist."); - } - if (roleAssignment.getPerson().equals(session.tryGetPerson()) - && roleAssignment.getRole().equals(RoleCode.ADMIN) - && roleAssignment.getDatabaseInstance() != null) - { - throw new UserFailureException( - "For safety reason you cannot give away your own omnipotence. " - + "Ask another instance admin to do that for you."); - } - roleAssignmentDAO.deleteRoleAssignment(roleAssignment); - } - - public final List<PersonPE> listPersons(final String sessionToken) - { - getSessionManager().getSession(sessionToken); - final List<PersonPE> persons = getDAOFactory().getPersonDAO().listPersons(); - Collections.sort(persons); - return persons; - } - - public final List<SampleTypePE> listSampleTypes(final String sessionToken) - { - getSessionManager().getSession(sessionToken); - return getDAOFactory().getSampleTypeDAO().listSampleTypes(true); - } - - public final List<SamplePE> listSamples(final String sessionToken, - final ListSampleCriteriaDTO criteria) - { - final Session session = getSessionManager().getSession(sessionToken); - final ISampleTable sampleTable = getBusinessObjectFactory().createSampleTable(session); - sampleTable.loadSamplesByCriteria(criteria); - sampleTable.enrichWithValidProcedure(); - sampleTable.enrichWithProperties(); - return sampleTable.getSamples(); - } - public final SampleGenerationDTO getSampleInfo(final String sessionToken, final SampleIdentifier identifier) { @@ -300,37 +91,6 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen return plugin.getSlaveServer().getSampleInfo(getDAOFactory(), session, sample); } - public final List<ExternalDataPE> listExternalData(final String sessionToken, - final SampleIdentifier identifier) - { - final Session session = getSessionManager().getSession(sessionToken); - final IExternalDataTable externalDataTable = - getBusinessObjectFactory().createExternalDataTable(session); - externalDataTable.loadBySampleIdentifier(identifier); - return externalDataTable.getExternalData(); - } - - public final List<SearchHit> listMatchingEntities(final String sessionToken, - final SearchableEntity[] searchableEntities, final String queryText) - { - getSessionManager().getSession(sessionToken); - final List<SearchHit> list = new ArrayList<SearchHit>(); - try - { - for (final SearchableEntity searchableEntity : searchableEntities) - { - final List<SearchHit> entities = - getDAOFactory().getHibernateSearchDAO().searchEntitiesByTerm( - searchableEntity.getMatchingEntityClass(), queryText); - list.addAll(entities); - } - } catch (final DataAccessException ex) - { - throw new UserFailureException(ex.getMostSpecificCause().getMessage(), ex); - } - return list; - } - public final void registerSample(final String sessionToken, final SampleToRegisterDTO newSample) { final Session session = getSessionManager().getSession(sessionToken); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerLogger.java index 2a7955e15d46a31d159ad0d9aa1d6a8c874def2c..c183b5417332c8f0ce5b30180c899fc0c4d2bbdb 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerLogger.java @@ -16,28 +16,11 @@ package ch.systemsx.cisd.openbis.plugin.generic.server; -import java.util.Arrays; -import java.util.List; - import ch.systemsx.cisd.authentication.ISessionManager; import ch.systemsx.cisd.openbis.generic.server.AbstractServerLogger; -import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.ListSampleCriteriaDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SearchHit; -import ch.systemsx.cisd.openbis.generic.shared.dto.SearchableEntity; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; @@ -62,96 +45,6 @@ final class GenericServerLogger extends AbstractServerLogger implements IGeneric // IGenericServer // - public List<GroupPE> listGroups(final String sessionToken, - final DatabaseInstanceIdentifier identifier) - { - final String command = "list_groups"; - if (identifier == null || identifier.getDatabaseInstanceCode() == null) - { - logAccess(sessionToken, command); - } else - { - logAccess(sessionToken, command, "DATABASE-INSTANCE(%s)", identifier); - } - return null; - } - - public void registerGroup(final String sessionToken, final String groupCode, - final String descriptionOrNull, final String groupLeaderOrNull) - { - logTracking(sessionToken, "register_group", "CODE(%s)", groupCode); - } - - public List<PersonPE> listPersons(final String sessionToken) - { - logAccess(sessionToken, "list_persons"); - return null; - } - - public void registerPerson(final String sessionToken, final String userID) - { - logTracking(sessionToken, "register_person", "CODE(%s)", userID); - - } - - public List<RoleAssignmentPE> listRoles(final String sessionToken) - { - logAccess(sessionToken, "list_roles"); - return null; - } - - public void registerGroupRole(final String sessionToken, final RoleCode roleCode, - final GroupIdentifier groupIdentifier, final String person) - { - logTracking(sessionToken, "register_role", "ROLE(%s) GROUP(%s) PERSON(%s)", roleCode, - groupIdentifier, person); - - } - - public void registerInstanceRole(final String sessionToken, final RoleCode roleCode, - final String person) - { - logTracking(sessionToken, "register_role", "ROLE(%s) PERSON(%s)", roleCode, person); - - } - - public void deleteGroupRole(final String sessionToken, final RoleCode roleCode, - final GroupIdentifier groupIdentifier, final String person) - { - logTracking(sessionToken, "delete_role", "ROLE(%s) GROUP(%s) PERSON(%s)", roleCode, - groupIdentifier, person); - - } - - public void deleteInstanceRole(final String sessionToken, final RoleCode roleCode, - final String person) - { - logTracking(sessionToken, "delete_role", "ROLE(%s) PERSON(%s)", roleCode, person); - - } - - public final List<SampleTypePE> listSampleTypes(final String sessionToken) - { - logAccess(sessionToken, "list_sample_types"); - return null; - } - - public final List<SamplePE> listSamples(final String sessionToken, - final ListSampleCriteriaDTO criteria) - { - logAccess(sessionToken, "list_samples", "TYPE(%s) OWNERS(%s)", criteria.getSampleType(), - criteria.getOwnerIdentifiers()); - return null; - } - - public final List<SamplePropertyPE> listSamplesProperties(final String sessionToken, - final ListSampleCriteriaDTO criteria, final List<PropertyTypePE> propertyCodes) - { - logAccess(sessionToken, "list_samples_properties", "CRITERIA(%s) PROPERTIES(%s)", criteria, - propertyCodes.size()); - return null; - } - public final SampleGenerationDTO getSampleInfo(final String sessionToken, final SampleIdentifier identifier) { @@ -159,23 +52,7 @@ final class GenericServerLogger extends AbstractServerLogger implements IGeneric return null; } - public final List<ExternalDataPE> listExternalData(final String sessionToken, - final SampleIdentifier identifier) - { - logTracking(sessionToken, "list_external_data", "IDENTIFIER(%s)", identifier); - return null; - } - - public final List<SearchHit> listMatchingEntities(final String sessionToken, - final SearchableEntity[] searchableEntities, final String queryText) - { - logTracking(sessionToken, "list_matching_entities", - "SEARCHABLE-ENTITIES(%s) QUERY-TEXT(%s)", Arrays.toString(searchableEntities), - queryText); - return null; - } - - public void registerSample(String sessionToken, SampleToRegisterDTO newSample) + public void registerSample(final String sessionToken, final SampleToRegisterDTO newSample) { logTracking(sessionToken, "register_sample", "SAMPLE_TYPE(%s) SAMPLE(%S)", newSample .getSampleTypeCode(), newSample.getSampleIdentifier()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java index c2448fa4e05e27f43cc61b108b7913b01fc0911d..2919d0b6869958312a30cdaad3faaf232668413c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java @@ -16,33 +16,16 @@ package ch.systemsx.cisd.openbis.plugin.generic.shared; -import java.util.List; - import org.springframework.transaction.annotation.Transactional; import ch.systemsx.cisd.openbis.generic.shared.IServer; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard; -import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.ReturnValueFilter; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.GroupIdentifierPredicate; import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleToRegisterDTOPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.GroupValidator; -import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.MatchingEntityValidator; -import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.ListSampleCriteriaDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.SearchHit; -import ch.systemsx.cisd.openbis.generic.shared.dto.SearchableEntity; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; /** @@ -52,89 +35,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; */ public interface IGenericServer extends IServer { - /** - * Returns all groups which belong to the specified database instance. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - @ReturnValueFilter(validatorClass = GroupValidator.class) - public List<GroupPE> listGroups(String sessionToken, DatabaseInstanceIdentifier identifier); - - /** - * Registers a new group with specified code and optional description and group leader ID. - */ - @Transactional - @RolesAllowed(RoleSet.INSTANCE_ADMIN) - public void registerGroup(String sessionToken, String groupCode, String descriptionOrNull, - String groupLeaderOrNull); - - /** - * Returns all persons from current instance. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - public List<PersonPE> listPersons(String sessionToken); - - /** - * Registers a new person. - */ - @Transactional - @RolesAllowed(RoleSet.INSTANCE_ADMIN) - public void registerPerson(String sessionToken, String userID); - - /** - * Returns a list of all roles. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.GROUP_ADMIN) - public List<RoleAssignmentPE> listRoles(String sessionToken); - - /** - * Registers a new group role. - */ - @Transactional - @RolesAllowed(RoleSet.GROUP_ADMIN) - public void registerGroupRole(String sessionToken, RoleCode roleCode, - @AuthorizationGuard(guardClass = GroupIdentifierPredicate.class) - GroupIdentifier identifier, String person); - - /** - * Registers a new instance role. - */ - @Transactional - @RolesAllowed(RoleSet.INSTANCE_ADMIN) - public void registerInstanceRole(String sessionToken, RoleCode roleCode, String person); - - /** - * Deletes role described by given role code, group identifier and user id. - */ - @Transactional - @RolesAllowed(RoleSet.GROUP_ADMIN) - public void deleteGroupRole(String sessionToken, RoleCode roleCode, - @AuthorizationGuard(guardClass = GroupIdentifierPredicate.class) - GroupIdentifier groupIdentifier, String person); - - /** - * Deletes role described by given role code and user id. - */ - @Transactional - @RolesAllowed(RoleSet.INSTANCE_ADMIN) - public void deleteInstanceRole(String sessionToken, RoleCode roleCode, String person); - - /** - * Lists sample types which are appropriate for listing. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - public List<SampleTypePE> listSampleTypes(String sessionToken); - - /** - * Lists samples using given configuration.No properties are loaded. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - public List<SamplePE> listSamples(final String sessionToken, - final ListSampleCriteriaDTO criteria); /** * For given {@link SampleIdentifier} returns the corresponding {@link SamplePE}. @@ -144,23 +44,6 @@ public interface IGenericServer extends IServer public SampleGenerationDTO getSampleInfo(final String sessionToken, final SampleIdentifier identifier); - /** - * For given {@link SampleIdentifier} returns the corresponding list of {@link ExternalDataPE}. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - public List<ExternalDataPE> listExternalData(final String sessionToken, - final SampleIdentifier identifier); - - /** - * Performs an <i>Hibernate Search</i> based on given parameters. - */ - @Transactional(readOnly = true) - @RolesAllowed(RoleSet.OBSERVER) - @ReturnValueFilter(validatorClass = MatchingEntityValidator.class) - public List<SearchHit> listMatchingEntities(final String sessionToken, - final SearchableEntity[] searchableEntities, final String queryText); - /** * Registers a new sample. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java index 731c1662f7a420174a011384e691a65f6c7b4c09..1b9397f707e72edf0c7ecae9030222e4e81905d8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.plugin.screening.client.web.client; import ch.systemsx.cisd.openbis.generic.client.web.client.IClientService; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Sample; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleGeneration; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleToRegister; import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; /** @@ -34,4 +35,9 @@ public interface IScreeningClientService extends IClientService */ public SampleGeneration getSampleInfo(final String sampleIdentifier) throws UserFailureException; + + /** + * Registers a new sample. + */ + public void registerSample(final SampleToRegister sample) throws UserFailureException; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java index 04f435b6e3eb0e31cb2d46ccda5ba02cd3e4840e..f6b47d58d0f5d75eb19be02bbde2abf96fe35277 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java @@ -20,6 +20,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.IClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleGeneration; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleToRegister; +import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; +import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientService; /** * Service interface for the <i>generic</i> <i>GWT</i> client. @@ -32,4 +35,10 @@ public interface IScreeningClientServiceAsync extends IClientServiceAsync /** @see IScreeningClientService#getSampleInfo(String) */ public void getSampleInfo(final String sampleIdentifier, final AsyncCallback<SampleGeneration> callback); + + /** + * @see IGenericClientService#registerSample(SampleToRegister) + */ + public void registerSample(final SampleToRegister sample, + final AsyncCallback<Void> asyncCallback) throws UserFailureException; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/ClientPluginFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/ClientPluginFactory.java index 8328698b0b0237c70a8211287256d52568526581..773ae23260809ae70da68407754d46d6be4ab630 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/ClientPluginFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/ClientPluginFactory.java @@ -110,7 +110,7 @@ public final class ClientPluginFactory extends }; } - public Widget createRegistrationClientForSampleType(SampleType sampleTypeCode) + public Widget createRegistrationClientForSampleType(final SampleType sampleTypeCode) { return new DummyComponent(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java index 173161e678603005339d9a57b75f66fa686c10dc..7386446390d2a96bbbab058f70971d7cc682aafd 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java @@ -22,8 +22,10 @@ import org.springframework.stereotype.Component; import ch.systemsx.cisd.common.utilities.BeanUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleGeneration; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleToRegister; import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; import ch.systemsx.cisd.openbis.generic.client.web.server.util.DtoConverters; +import ch.systemsx.cisd.openbis.generic.client.web.server.util.SampleToRegisterTranslator; import ch.systemsx.cisd.openbis.generic.client.web.server.util.UserFailureExceptionTranslator; import ch.systemsx.cisd.openbis.generic.shared.IServer; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; @@ -76,4 +78,17 @@ public final class ScreeningClientService extends AbstractClientService implemen throw UserFailureExceptionTranslator.translate(e); } } + + public final void registerSample(final SampleToRegister sample) throws UserFailureException + { + try + { + final String sessionToken = getSessionToken(); + screeningServer.registerSample(sessionToken, SampleToRegisterTranslator + .translate(sample)); + } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java index f7fc323f10f541e6c5b0fa276f68b4a0a55b39fa..c97f61ac4ef502d96ad06ce2c1d1c10c6aed1fc9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java @@ -19,12 +19,14 @@ package ch.systemsx.cisd.openbis.plugin.screening.server; import org.springframework.stereotype.Component; import ch.systemsx.cisd.authentication.ISessionManager; +import ch.systemsx.cisd.common.exceptions.NotImplementedException; import ch.systemsx.cisd.openbis.generic.server.AbstractServer; import ch.systemsx.cisd.openbis.generic.server.business.bo.IGenericBusinessObjectFactory; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.plugin.ISampleServerPlugin; @@ -88,4 +90,9 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl SampleServerPluginRegistry.getPlugin(this, sample.getSampleType()); return plugin.getSlaveServer().getSampleInfo(getDAOFactory(), session, sample); } + + public final void registerSample(final String sessionToken, final SampleToRegisterDTO newSample) + { + throw new NotImplementedException(); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java index 52551fa00785d1d8c2e52d51dbe51497870f5ede..8002c625285ddfac6122d6024b658f9bf502a108 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.plugin.screening.server; import ch.systemsx.cisd.authentication.ISessionManager; import ch.systemsx.cisd.openbis.generic.server.AbstractServerLogger; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.plugin.screening.shared.IScreeningServer; @@ -40,9 +41,16 @@ final class ScreeningServerLogger extends AbstractServerLogger implements IScree // IScreeningServer // - public final SampleGenerationDTO getSampleInfo(final String sessionToken, final SampleIdentifier identifier) + public final SampleGenerationDTO getSampleInfo(final String sessionToken, + final SampleIdentifier identifier) { - logTracking(sessionToken, "get_sample_info", "CODE(%s)", identifier); + logTracking(sessionToken, "get_plate_info", "CODE(%s)", identifier); return null; } + + public void registerSample(final String sessionToken, final SampleToRegisterDTO newSample) + { + logTracking(sessionToken, "register_plate", "PLATE_TYPE(%s) PLATE(%S)", newSample + .getSampleTypeCode(), newSample.getSampleIdentifier()); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java index 9fab4688bd87fd1835d7bd455f7510cf72e4cb8e..e01e6c52e8b49698e018ef175f7b94b626a5d5f7 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java @@ -24,8 +24,10 @@ import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.Authoriz import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed; import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleOwnerIdentifierPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleToRegisterDTOPredicate; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; /** @@ -48,4 +50,13 @@ public interface IScreeningServer extends IServer SampleGenerationDTO getSampleInfo(final String sessionToken, @AuthorizationGuard(guardClass = SampleOwnerIdentifierPredicate.class) final SampleIdentifier sampleIdentifier) throws UserFailureException; + + /** + * Registers a new sample. + */ + @Transactional + @RolesAllowed(RoleSet.USER) + public void registerSample(final String sessionToken, + @AuthorizationGuard(guardClass = SampleToRegisterDTOPredicate.class) + final SampleToRegisterDTO newSample); } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..964b101440bdc5545945cef8a417d48eb67f9ff5 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java @@ -0,0 +1,398 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed 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 ch.systemsx.cisd.openbis.generic.server; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.jmock.Expectations; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.shared.AbstractServerTestCase; +import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; +import ch.systemsx.cisd.openbis.generic.shared.dto.Session; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; + +/** + * Test cases for corresponding {@link CommonServer} class. + * + * @author Franz-Josef Elmer + */ +public final class CommonServerTest extends AbstractServerTestCase +{ + + private final ICommonServer createServer() + { + return new CommonServer(authenticationService, sessionManager, daoFactory, boFactory); + } + + private final static PersonPE createSystemUser() + { + final PersonPE systemPerson = new PersonPE(); + systemPerson.setUserId(PersonPE.SYSTEM_USER_ID); + return systemPerson; + } + + @Test + public void testLogout() + { + context.checking(new Expectations() + { + { + one(sessionManager).closeSession(SESSION_TOKEN); + } + }); + createServer().logout(SESSION_TOKEN); + + context.assertIsSatisfied(); + } + + @Test + public void testTryToAuthenticateWhichFailed() + { + final String user = "user"; + final String password = "password"; + context.checking(new Expectations() + { + { + one(sessionManager).tryToOpenSession(user, password); + will(returnValue(null)); + } + }); + + assertEquals(null, createServer().tryToAuthenticate(user, password)); + + context.assertIsSatisfied(); + } + + @Test + public void testFirstTryToAuthenticate() + { + final String user = "user"; + final String password = "password"; + final Session session = createExampleSession(); + final PersonPE systemPerson = createSystemUser(); + final PersonPE person = createPersonFromPrincipal(PRINCIPAL); + final RoleAssignmentPE roleAssignment = new RoleAssignmentPE(); + roleAssignment.setPerson(person); + roleAssignment.setDatabaseInstance(homeDatabaseInstance); + roleAssignment.setRegistrator(systemPerson); + roleAssignment.setRole(RoleCode.ADMIN); + context.checking(new Expectations() + { + { + one(sessionManager).tryToOpenSession(user, password); + will(returnValue(SESSION_TOKEN)); + + one(sessionManager).getSession(SESSION_TOKEN); + will(returnValue(session)); + + one(personDAO).listPersons(); + will(returnValue(Arrays.asList(systemPerson))); // only 'system' in database + + one(personDAO).tryFindPersonByUserId(user); // first login + will(returnValue(null)); + + one(personDAO).createPerson(person); + one(personDAO).updatePerson(person); + } + }); + + final Session s = createServer().tryToAuthenticate(user, password); + + assertEquals(person, s.tryGetPerson()); + assertEquals(roleAssignment, s.tryGetPerson().getRoleAssignments().iterator().next()); + + context.assertIsSatisfied(); + } + + @Test + public void testFirstTryToAuthenticateButNotFirstUser() + { + final String user = "user"; + final String password = "password"; + final Session session = createExampleSession(); + final PersonPE systemPerson = createSystemUser(); + final PersonPE person = createPersonFromPrincipal(PRINCIPAL); + context.checking(new Expectations() + { + { + one(sessionManager).tryToOpenSession(user, password); + will(returnValue(SESSION_TOKEN)); + + one(sessionManager).getSession(SESSION_TOKEN); + will(returnValue(session)); + + one(personDAO).listPersons(); + will(returnValue(Arrays.asList(systemPerson, person))); + + one(personDAO).tryFindPersonByUserId(user); // first login + will(returnValue(null)); + + one(personDAO).createPerson(person); + } + }); + + final Session s = createServer().tryToAuthenticate(user, password); + + assertEquals(person, s.tryGetPerson()); + + context.assertIsSatisfied(); + } + + @Test + public void testTryToAuthenticate() + { + final String user = "user"; + final String password = "password"; + final Session session = createExampleSession(); + final PersonPE systemPerson = createSystemUser(); + final PersonPE person = createPersonFromPrincipal(PRINCIPAL); + context.checking(new Expectations() + { + { + one(sessionManager).tryToOpenSession(user, password); + will(returnValue(SESSION_TOKEN)); + + one(sessionManager).getSession(SESSION_TOKEN); + will(returnValue(session)); + + one(personDAO).listPersons(); + will(returnValue(Arrays.asList(systemPerson, person))); + + one(personDAO).tryFindPersonByUserId(user); + will(returnValue(person)); + } + }); + assertEquals(null, session.tryGetPerson()); + + final Session s = createServer().tryToAuthenticate(user, password); + + assertSame(session, s); + assertEquals(person, s.tryGetPerson()); + + context.assertIsSatisfied(); + } + + @Test + public void testListGroups() + { + final PersonPE person = createPersonFromPrincipal(PRINCIPAL); + final DatabaseInstanceIdentifier identifier = DatabaseInstanceIdentifier.createHome(); + final GroupPE g1 = createGroup("g1", homeDatabaseInstance); + final GroupPE g2 = createGroup("g2", homeDatabaseInstance); + final Session session = prepareGetSession(); + session.setPerson(person); + person.setHomeGroup(g1); + g1.setId(42L); + context.checking(new Expectations() + { + { + one(groupDAO).listGroups(homeDatabaseInstance); + will(returnValue(Arrays.asList(g1, g2))); + } + }); + + final List<GroupPE> groups = createServer().listGroups(SESSION_TOKEN, identifier); + + assertSame(g1, groups.get(0)); + assertSame(g2, groups.get(1)); + assertEquals(2, groups.size()); + assertEquals(true, g1.isHome().booleanValue()); + assertEquals(false, g2.isHome().booleanValue()); + + context.assertIsSatisfied(); + } + + @Test + public void testRegisterGroup() + { + final Session session = prepareGetSession(); + final String groupCode = "group"; + final String description = "description"; + final String leader = "leader"; + context.checking(new Expectations() + { + { + one(boFactory).createGroupBO(session); + will(returnValue(groupBO)); + + one(groupBO).define(groupCode, description, leader); + one(groupBO).save(); + } + }); + + createServer().registerGroup(SESSION_TOKEN, groupCode, description, leader); + + context.assertIsSatisfied(); + } + + @Test + public void testListPersons() + { + final PersonPE person = createPersonFromPrincipal(PRINCIPAL); + prepareGetSession(); + context.checking(new Expectations() + { + { + one(personDAO).listPersons(); + will(returnValue(Arrays.asList(person))); + } + }); + + final List<PersonPE> persons = createServer().listPersons(SESSION_TOKEN); + + assertSame(person, persons.get(0)); + assertEquals(1, persons.size()); + + context.assertIsSatisfied(); + } + + @Test + public void testRegisterPerson() + { + prepareGetSession(); + context.checking(new Expectations() + { + { + one(personDAO).tryFindPersonByUserId(USER_ID); + will(returnValue(null)); + + final String applicationToken = "application-token"; + one(authenticationService).authenticateApplication(); + will(returnValue(applicationToken)); + + one(authenticationService).getPrincipal(applicationToken, USER_ID); + will(returnValue(PRINCIPAL)); + + final PersonPE person = createPersonFromPrincipal(PRINCIPAL); + one(personDAO).createPerson(person); + } + }); + + createServer().registerPerson(SESSION_TOKEN, USER_ID); + + context.assertIsSatisfied(); + } + + @Test + public void testRegisterExistingPerson() + { + prepareGetSession(); + context.checking(new Expectations() + { + { + one(personDAO).tryFindPersonByUserId(USER_ID); + will(returnValue(createPersonFromPrincipal(PRINCIPAL))); + } + }); + + try + { + createServer().registerPerson(SESSION_TOKEN, USER_ID); + fail("UserFailureException expected"); + } catch (final UserFailureException e) + { + assertEquals("Person '" + USER_ID + "' already exists.", e.getMessage()); + } + + context.assertIsSatisfied(); + } + + @Test + public void testRegisterUnknownPerson() + { + prepareGetSession(); + context.checking(new Expectations() + { + { + one(personDAO).tryFindPersonByUserId(USER_ID); + will(returnValue(null)); + + final String applicationToken = "application-token"; + one(authenticationService).authenticateApplication(); + will(returnValue(applicationToken)); + + one(authenticationService).getPrincipal(applicationToken, USER_ID); + will(throwException(new IllegalArgumentException())); + } + }); + + try + { + createServer().registerPerson(SESSION_TOKEN, USER_ID); + fail("UserFailureException expected"); + } catch (final UserFailureException e) + { + assertEquals("Person '" + USER_ID + "' unknown by the authentication service.", e + .getMessage()); + } + + context.assertIsSatisfied(); + } + + @Test + public void testListRoles() + { + prepareGetSession(); + final RoleAssignmentPE role = new RoleAssignmentPE(); + context.checking(new Expectations() + { + { + one(roleAssignmentDAO).listRoleAssignments(); + will(returnValue(Arrays.asList(role))); + } + }); + + final List<RoleAssignmentPE> roles = createServer().listRoles(SESSION_TOKEN); + + assertSame(role, roles.get(0)); + assertEquals(1, roles.size()); + + context.assertIsSatisfied(); + } + + @Test + public final void testListExternalData() + { + final Session session = prepareGetSession(); + final SampleIdentifier sampleIdentifier = createSampleIdentifier(); + context.checking(new Expectations() + { + { + one(boFactory).createExternalDataTable(session); + will(returnValue(externalDataTable)); + + one(externalDataTable).loadBySampleIdentifier(sampleIdentifier); + + one(externalDataTable).getExternalData(); + will(returnValue(new ArrayList<DataPE>())); + } + }); + createServer().listExternalData(SESSION_TOKEN, sampleIdentifier); + context.assertIsSatisfied(); + } + +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java index fbeb913f2f32bef21a40630e15555d1875c2752f..bd6d16975dafce1c805717a526e4fb9a4cf8d605 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java @@ -16,25 +16,14 @@ package ch.systemsx.cisd.openbis.plugin.generic.server; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import org.jmock.Expectations; import org.testng.annotations.Test; -import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.shared.AbstractServerTestCase; -import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleToRegisterDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; @@ -48,333 +37,7 @@ public final class GenericServerTest extends AbstractServerTestCase private final IGenericServer createServer() { - return new GenericServer(authenticationService, sessionManager, daoFactory, boFactory); - } - - private final static PersonPE createSystemUser() - { - final PersonPE systemPerson = new PersonPE(); - systemPerson.setUserId(PersonPE.SYSTEM_USER_ID); - return systemPerson; - } - - @Test - public void testLogout() - { - context.checking(new Expectations() - { - { - one(sessionManager).closeSession(SESSION_TOKEN); - } - }); - createServer().logout(SESSION_TOKEN); - - context.assertIsSatisfied(); - } - - @Test - public void testTryToAuthenticateWhichFailed() - { - final String user = "user"; - final String password = "password"; - context.checking(new Expectations() - { - { - one(sessionManager).tryToOpenSession(user, password); - will(returnValue(null)); - } - }); - - assertEquals(null, createServer().tryToAuthenticate(user, password)); - - context.assertIsSatisfied(); - } - - @Test - public void testFirstTryToAuthenticate() - { - final String user = "user"; - final String password = "password"; - final Session session = createExampleSession(); - final PersonPE systemPerson = createSystemUser(); - final PersonPE person = createPersonFromPrincipal(PRINCIPAL); - final RoleAssignmentPE roleAssignment = new RoleAssignmentPE(); - roleAssignment.setPerson(person); - roleAssignment.setDatabaseInstance(homeDatabaseInstance); - roleAssignment.setRegistrator(systemPerson); - roleAssignment.setRole(RoleCode.ADMIN); - context.checking(new Expectations() - { - { - one(sessionManager).tryToOpenSession(user, password); - will(returnValue(SESSION_TOKEN)); - - one(sessionManager).getSession(SESSION_TOKEN); - will(returnValue(session)); - - one(personDAO).listPersons(); - will(returnValue(Arrays.asList(systemPerson))); // only 'system' in database - - one(personDAO).tryFindPersonByUserId(user); // first login - will(returnValue(null)); - - one(personDAO).createPerson(person); - one(personDAO).updatePerson(person); - } - }); - - final Session s = createServer().tryToAuthenticate(user, password); - - assertEquals(person, s.tryGetPerson()); - assertEquals(roleAssignment, s.tryGetPerson().getRoleAssignments().iterator().next()); - - context.assertIsSatisfied(); - } - - @Test - public void testFirstTryToAuthenticateButNotFirstUser() - { - final String user = "user"; - final String password = "password"; - final Session session = createExampleSession(); - final PersonPE systemPerson = createSystemUser(); - final PersonPE person = createPersonFromPrincipal(PRINCIPAL); - context.checking(new Expectations() - { - { - one(sessionManager).tryToOpenSession(user, password); - will(returnValue(SESSION_TOKEN)); - - one(sessionManager).getSession(SESSION_TOKEN); - will(returnValue(session)); - - one(personDAO).listPersons(); - will(returnValue(Arrays.asList(systemPerson, person))); - - one(personDAO).tryFindPersonByUserId(user); // first login - will(returnValue(null)); - - one(personDAO).createPerson(person); - } - }); - - final Session s = createServer().tryToAuthenticate(user, password); - - assertEquals(person, s.tryGetPerson()); - - context.assertIsSatisfied(); - } - - @Test - public void testTryToAuthenticate() - { - final String user = "user"; - final String password = "password"; - final Session session = createExampleSession(); - final PersonPE systemPerson = createSystemUser(); - final PersonPE person = createPersonFromPrincipal(PRINCIPAL); - context.checking(new Expectations() - { - { - one(sessionManager).tryToOpenSession(user, password); - will(returnValue(SESSION_TOKEN)); - - one(sessionManager).getSession(SESSION_TOKEN); - will(returnValue(session)); - - one(personDAO).listPersons(); - will(returnValue(Arrays.asList(systemPerson, person))); - - one(personDAO).tryFindPersonByUserId(user); - will(returnValue(person)); - } - }); - assertEquals(null, session.tryGetPerson()); - - final Session s = createServer().tryToAuthenticate(user, password); - - assertSame(session, s); - assertEquals(person, s.tryGetPerson()); - - context.assertIsSatisfied(); - } - - @Test - public void testListGroups() - { - final PersonPE person = createPersonFromPrincipal(PRINCIPAL); - final DatabaseInstanceIdentifier identifier = DatabaseInstanceIdentifier.createHome(); - final GroupPE g1 = createGroup("g1", homeDatabaseInstance); - final GroupPE g2 = createGroup("g2", homeDatabaseInstance); - final Session session = prepareGetSession(); - session.setPerson(person); - person.setHomeGroup(g1); - g1.setId(42L); - context.checking(new Expectations() - { - { - one(groupDAO).listGroups(homeDatabaseInstance); - will(returnValue(Arrays.asList(g1, g2))); - } - }); - - final List<GroupPE> groups = createServer().listGroups(SESSION_TOKEN, identifier); - - assertSame(g1, groups.get(0)); - assertSame(g2, groups.get(1)); - assertEquals(2, groups.size()); - assertEquals(true, g1.isHome().booleanValue()); - assertEquals(false, g2.isHome().booleanValue()); - - context.assertIsSatisfied(); - } - - @Test - public void testRegisterGroup() - { - final Session session = prepareGetSession(); - final String groupCode = "group"; - final String description = "description"; - final String leader = "leader"; - context.checking(new Expectations() - { - { - one(boFactory).createGroupBO(session); - will(returnValue(groupBO)); - - one(groupBO).define(groupCode, description, leader); - one(groupBO).save(); - } - }); - - createServer().registerGroup(SESSION_TOKEN, groupCode, description, leader); - - context.assertIsSatisfied(); - } - - @Test - public void testListPersons() - { - final PersonPE person = createPersonFromPrincipal(PRINCIPAL); - prepareGetSession(); - context.checking(new Expectations() - { - { - one(personDAO).listPersons(); - will(returnValue(Arrays.asList(person))); - } - }); - - final List<PersonPE> persons = createServer().listPersons(SESSION_TOKEN); - - assertSame(person, persons.get(0)); - assertEquals(1, persons.size()); - - context.assertIsSatisfied(); - } - - @Test - public void testRegisterPerson() - { - prepareGetSession(); - context.checking(new Expectations() - { - { - one(personDAO).tryFindPersonByUserId(USER_ID); - will(returnValue(null)); - - final String applicationToken = "application-token"; - one(authenticationService).authenticateApplication(); - will(returnValue(applicationToken)); - - one(authenticationService).getPrincipal(applicationToken, USER_ID); - will(returnValue(PRINCIPAL)); - - final PersonPE person = createPersonFromPrincipal(PRINCIPAL); - one(personDAO).createPerson(person); - } - }); - - createServer().registerPerson(SESSION_TOKEN, USER_ID); - - context.assertIsSatisfied(); - } - - @Test - public void testRegisterExistingPerson() - { - prepareGetSession(); - context.checking(new Expectations() - { - { - one(personDAO).tryFindPersonByUserId(USER_ID); - will(returnValue(createPersonFromPrincipal(PRINCIPAL))); - } - }); - - try - { - createServer().registerPerson(SESSION_TOKEN, USER_ID); - fail("UserFailureException expected"); - } catch (final UserFailureException e) - { - assertEquals("Person '" + USER_ID + "' already exists.", e.getMessage()); - } - - context.assertIsSatisfied(); - } - - @Test - public void testRegisterUnknownPerson() - { - prepareGetSession(); - context.checking(new Expectations() - { - { - one(personDAO).tryFindPersonByUserId(USER_ID); - will(returnValue(null)); - - final String applicationToken = "application-token"; - one(authenticationService).authenticateApplication(); - will(returnValue(applicationToken)); - - one(authenticationService).getPrincipal(applicationToken, USER_ID); - will(throwException(new IllegalArgumentException())); - } - }); - - try - { - createServer().registerPerson(SESSION_TOKEN, USER_ID); - fail("UserFailureException expected"); - } catch (final UserFailureException e) - { - assertEquals("Person '" + USER_ID + "' unknown by the authentication service.", e - .getMessage()); - } - - context.assertIsSatisfied(); - } - - @Test - public void testListRoles() - { - prepareGetSession(); - final RoleAssignmentPE role = new RoleAssignmentPE(); - context.checking(new Expectations() - { - { - one(roleAssignmentDAO).listRoleAssignments(); - will(returnValue(Arrays.asList(role))); - } - }); - - final List<RoleAssignmentPE> roles = createServer().listRoles(SESSION_TOKEN); - - assertSame(role, roles.get(0)); - assertEquals(1, roles.size()); - - context.assertIsSatisfied(); + return new GenericServer(sessionManager, daoFactory, boFactory); } @Test @@ -409,27 +72,6 @@ public final class GenericServerTest extends AbstractServerTestCase context.assertIsSatisfied(); } - @Test - public final void testListExternalData() - { - final Session session = prepareGetSession(); - final SampleIdentifier sampleIdentifier = createSampleIdentifier(); - context.checking(new Expectations() - { - { - one(boFactory).createExternalDataTable(session); - will(returnValue(externalDataTable)); - - one(externalDataTable).loadBySampleIdentifier(sampleIdentifier); - - one(externalDataTable).getExternalData(); - will(returnValue(new ArrayList<DataPE>())); - } - }); - createServer().listExternalData(SESSION_TOKEN, sampleIdentifier); - context.assertIsSatisfied(); - } - @Test public final void testRegisterSample() {