From 0d2e41e2434f7ddf44f5869e338ea65ce86b51e5 Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Mon, 28 Sep 2009 10:08:05 +0000 Subject: [PATCH] [LMS-1163] fixed filter validator SVN: 12727 --- .../validator/FilterValidator.java | 9 ++-- .../generic/shared/basic/dto/Person.java | 45 ++++++++++++++++++- .../shared/translator/PersonTranslator.java | 5 ++- .../generic/server/CommonServerTest.java | 2 + .../business/bo/AuthorizationGroupBOTest.java | 7 +-- .../server/business/bo/MaterialTableTest.java | 6 +-- .../shared/AbstractServerTestCase.java | 3 +- .../generic/shared/CommonTestUtils.java | 14 ++++-- .../ExternalDataTranslatorTest.java | 1 + 9 files changed, 68 insertions(+), 24 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/validator/FilterValidator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/validator/FilterValidator.java index 97ad702c968..838782b9891 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/validator/FilterValidator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/authorization/validator/FilterValidator.java @@ -33,7 +33,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode; */ public final class FilterValidator extends AbstractValidator<Filter> { - // TODO 2009-09-09, IA: add tests // // IValidator // @@ -48,11 +47,10 @@ public final class FilterValidator extends AbstractValidator<Filter> private boolean isRegistrator(final PersonPE person, final Filter value) { - // Comparison between PersonPE and Person will always return false!!! - // return person.equals(value.getRegistrator()); - // FIXME 2009-09-22, Piotr Buczek: Person has no database instance code to compare with PersonPE Person registrator = value.getRegistrator(); - return person.getUserId().equals(registrator.getUserId()); + return person.getUserId().equals(registrator.getUserId()) + && person.getDatabaseInstance().getCode().equals( + registrator.getDatabaseInstance().getCode()); } public boolean isInstanceAdmin(final PersonPE person, final DatabaseInstance databaseInstance) @@ -60,7 +58,6 @@ public final class FilterValidator extends AbstractValidator<Filter> final Set<RoleAssignmentPE> roleAssignments = person.getAllPersonRoles(); for (final RoleAssignmentPE roleAssignment : roleAssignments) { - // TODO why do we use UUID instead of CODE if both are unique? final DatabaseInstancePE roleInstance = roleAssignment.getDatabaseInstance(); if (roleInstance != null && roleInstance.getUuid().equals(databaseInstance.getUuid()) && roleAssignment.getRole().equals(RoleCode.ADMIN)) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Person.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Person.java index b5fb913a069..8fdde3892a9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Person.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/Person.java @@ -21,7 +21,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; /** * The <i>GWT</i> equivalent to {@link PersonPE}. * - * @author Franz-Josef Elmer + * @author Franz-Josef Elmer */ public class Person extends AbstractRegistrationHolder implements Comparable<Person> { @@ -35,6 +35,8 @@ public class Person extends AbstractRegistrationHolder implements Comparable<Per private String userId; + private DatabaseInstance databaseInstance; + public final String getFirstName() { return firstName; @@ -75,6 +77,43 @@ public class Person extends AbstractRegistrationHolder implements Comparable<Per this.userId = code; } + public DatabaseInstance getDatabaseInstance() + { + return databaseInstance; + } + + public void setDatabaseInstance(DatabaseInstance databaseInstance) + { + this.databaseInstance = databaseInstance; + } + + // + // Object + // + + @Override + public boolean equals(Object obj) + { + assert getDatabaseInstance() != null; + if (obj == this) + { + return true; + } + if (obj instanceof Person == false) + { + return false; + } + final Person that = (Person) obj; + return getUserId().equals(that.getUserId()) + && getDatabaseInstance().equals(that.getDatabaseInstance()); + } + + @Override + public int hashCode() + { + return getUserId().hashCode(); + } + @Override public String toString() { @@ -91,6 +130,10 @@ public class Person extends AbstractRegistrationHolder implements Comparable<Per return result.toString(); } + // + // Comparable + // + public int compareTo(final Person o) { if (o == null) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java index 3a23f31bb0e..a3a17844c91 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonTranslator.java @@ -28,7 +28,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; /** * A {@link Person} <---> {@link PersonPE} translator. * - * @author Franz-Josef Elmer + * @author Franz-Josef Elmer */ public class PersonTranslator { @@ -63,6 +63,8 @@ public class PersonTranslator result.setLastName(StringEscapeUtils.escapeHtml(person.getLastName())); result.setEmail(StringEscapeUtils.escapeHtml(person.getEmail())); result.setUserId(StringEscapeUtils.escapeHtml(person.getUserId())); + result.setDatabaseInstance(DatabaseInstanceTranslator.translate(person + .getDatabaseInstance())); result.setRegistrationDate(person.getRegistrationDate()); if (recursively) { @@ -70,5 +72,4 @@ public class PersonTranslator } return result; } - } 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 index dac7f0a4684..f1071b5fbc6 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java @@ -141,6 +141,7 @@ public final class CommonServerTest extends AbstractServerTestCase { final PersonPE systemPerson = new PersonPE(); systemPerson.setUserId(PersonPE.SYSTEM_USER_ID); + systemPerson.setDatabaseInstance(CommonTestUtils.createHomeDatabaseInstance()); return systemPerson; } @@ -381,6 +382,7 @@ public final class CommonServerTest extends AbstractServerTestCase assertEquals(person.getFirstName(), persons.get(0).getFirstName()); assertEquals(person.getLastName(), persons.get(0).getLastName()); assertEquals(person.getEmail(), persons.get(0).getEmail()); + assertEquals(person.getDatabaseInstance(), persons.get(0).getDatabaseInstance()); assertEquals(1, persons.size()); context.assertIsSatisfied(); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AuthorizationGroupBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AuthorizationGroupBOTest.java index 6fcda181180..d0464a4e763 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AuthorizationGroupBOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AuthorizationGroupBOTest.java @@ -70,9 +70,7 @@ public final class AuthorizationGroupBOTest extends AbstractBOTest { { one(daoFactory).getHomeDatabaseInstance(); - DatabaseInstancePE dbInstance = - CommonTestUtils - .createDatabaseInstance(CommonTestUtils.HOME_DATABASE_INSTANCE_CODE); + DatabaseInstancePE dbInstance = CommonTestUtils.createHomeDatabaseInstance(); will(returnValue(dbInstance)); one(groupFactory).create(newAuthorizationGroup, ManagerTestTool.EXAMPLE_SESSION.tryGetPerson(), dbInstance); @@ -97,8 +95,7 @@ public final class AuthorizationGroupBOTest extends AbstractBOTest { final AuthorizationGroupBO bo = createBO(); - final DatabaseInstancePE homeDb = - CommonTestUtils.createDatabaseInstance(CommonTestUtils.HOME_DATABASE_INSTANCE_CODE); + final DatabaseInstancePE homeDb = CommonTestUtils.createHomeDatabaseInstance(); final NewAuthorizationGroup newAuthorizationGroup = createNewAuthorizationGroup(); final AuthorizationGroupPE authGroupPE = createAuthorizationGroup(); context.checking(new Expectations() diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialTableTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialTableTest.java index 9eb183c08e1..7064e981a88 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialTableTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MaterialTableTest.java @@ -90,8 +90,7 @@ public final class MaterialTableTest extends AbstractBOTest { { one(daoFactory).getHomeDatabaseInstance(); - will(returnValue(CommonTestUtils - .createDatabaseInstance(CommonTestUtils.HOME_DATABASE_INSTANCE_CODE))); + will(returnValue(CommonTestUtils.createHomeDatabaseInstance())); } }); createMaterialTable().add(newMaterials, materialType); @@ -127,8 +126,7 @@ public final class MaterialTableTest extends AbstractBOTest final MaterialPE material = new MaterialPE(); material.setCode(code); material.setMaterialType(materialType); - material.setDatabaseInstance(CommonTestUtils - .createDatabaseInstance(CommonTestUtils.HOME_DATABASE_INSTANCE_CODE)); + material.setDatabaseInstance(CommonTestUtils.createHomeDatabaseInstance()); material.setRegistrator(EXAMPLE_SESSION.tryGetPerson()); return material; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java index 32c605b9091..9021616d830 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/AbstractServerTestCase.java @@ -198,8 +198,7 @@ public abstract class AbstractServerTestCase extends AssertJUnit propertyTypeTable = context.mock(IPropertyTypeTable.class); materialTable = context.mock(IMaterialTable.class); - homeDatabaseInstance = - CommonTestUtils.createDatabaseInstance(CommonTestUtils.HOME_DATABASE_INSTANCE_CODE); + homeDatabaseInstance = CommonTestUtils.createHomeDatabaseInstance(); context.checking(new Expectations() { { diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java index 6f1c883dd34..35aca4a2c03 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java @@ -156,6 +156,11 @@ public class CommonTestUtils return databaseInstance; } + public static DatabaseInstancePE createHomeDatabaseInstance() + { + return createDatabaseInstance(HOME_DATABASE_INSTANCE_CODE); + } + static public PersonPE createPersonFromPrincipal(final Principal principal) { final PersonPE person = new PersonPE(); @@ -163,6 +168,7 @@ public class CommonTestUtils person.setFirstName(principal.getFirstName()); person.setLastName(principal.getLastName()); person.setEmail(principal.getEmail()); + person.setDatabaseInstance(createHomeDatabaseInstance()); return person; } @@ -185,7 +191,7 @@ public class CommonTestUtils { final ExperimentTypePE sampleTypePE = new ExperimentTypePE(); sampleTypePE.setCode(EXPERIMENT_TYPE); - sampleTypePE.setDatabaseInstance(createDatabaseInstance(HOME_DATABASE_INSTANCE_CODE)); + sampleTypePE.setDatabaseInstance(createHomeDatabaseInstance()); return sampleTypePE; } @@ -200,7 +206,7 @@ public class CommonTestUtils { VocabularyPE vocabulary = new VocabularyPE(); vocabulary.setCode(fullCode); - vocabulary.setDatabaseInstance(createDatabaseInstance(HOME_DATABASE_INSTANCE_CODE)); + vocabulary.setDatabaseInstance(createHomeDatabaseInstance()); if (terms != null) { vocabulary.setTerms(terms); @@ -220,7 +226,7 @@ public class CommonTestUtils { PropertyTypePE result = new PropertyTypePE(); result.setCode(fullCode); - result.setDatabaseInstance(createDatabaseInstance(HOME_DATABASE_INSTANCE_CODE)); + result.setDatabaseInstance(createHomeDatabaseInstance()); result.setType(createDataType(type)); result.setVocabulary(vocabularyOrNull); result.setMaterialType(materialTypeOrNull); @@ -312,7 +318,7 @@ public class CommonTestUtils final MaterialTypePE type = new MaterialTypePE(); type.setCode(MATERIAL_TYPE_VIRUS); - type.setDatabaseInstance(createDatabaseInstance(HOME_DATABASE_INSTANCE_CODE)); + type.setDatabaseInstance(createHomeDatabaseInstance()); return type; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/translator/ExternalDataTranslatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/translator/ExternalDataTranslatorTest.java index 9cb48237b15..8a1392cace9 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/translator/ExternalDataTranslatorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/translator/ExternalDataTranslatorTest.java @@ -112,6 +112,7 @@ public class ExternalDataTranslatorTest extends AssertJUnit invalidationPE.setRegistrationDate(new Date(3)); PersonPE personPE = new PersonPE(); personPE.setUserId("user"); + personPE.setDatabaseInstance(databaseInstancePE); invalidationPE.setRegistrator(personPE); samplePE.setInvalidation(invalidationPE); externalDataPE.setSampleAcquiredFrom(samplePE); -- GitLab