From d1b3622b9862ea46b8caefd6aa02924c98689a71 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Thu, 4 Oct 2012 12:36:31 +0000 Subject: [PATCH] BIS-222 - Make STORAGE_CONFIRMED available in dataset search for admins SVN: 26989 --- .../model/DetailedSearchFieldComboModel.java | 13 ++- .../search/DetailedSearchCriterionWidget.java | 51 ++++------- .../DetailedSearchFieldsSelectionWidget.java | 45 +++++++++- .../web/client/application/util/GWTUtils.java | 28 +++--- .../generic/client/web/client/dto/User.java | 14 +++ .../web/server/AbstractClientService.java | 1 + .../AbstractExternalDataProvider.java | 5 +- .../generic/server/AbstractServer.java | 3 + .../search/detailed/IndexFieldNameHelper.java | 2 + .../dto/DataSetAttributeSearchFieldKind.java | 46 ++++++++-- .../ExperimentAttributeSearchFieldKind.java | 43 +++++++-- .../basic/dto/IAttributeSearchFieldKind.java | 3 +- .../basic/dto/ISearchFieldAvailability.java | 27 ++++++ .../dto/ISearchFieldCriterionFactory.java | 28 ++++++ .../shared/basic/dto/ISearchFieldKind.java | 30 +++++++ .../dto/MaterialAttributeSearchFieldKind.java | 43 +++++++-- .../generic/shared/basic/dto/PersonRole.java | 75 ++++++++++++++++ .../generic/shared/basic/dto/PersonRoles.java | 60 +++++++++++++ .../dto/SampleAttributeSearchFieldKind.java | 43 +++++++-- .../dto/SearchFieldAvailableForAdmins.java | 31 +++++++ .../SearchFieldBooleanCriterionFactory.java | 41 +++++++++ .../dto/SearchFieldDateCriterionFactory.java | 58 +++++++++++++ .../generic/shared/dto/ExternalDataPE.java | 4 + .../generic/shared/dto/SessionContextDTO.java | 13 +++ .../dto/hibernate/SearchFieldConstants.java | 2 + .../translator/PersonRolesTranslator.java | 87 +++++++++++++++++++ 26 files changed, 720 insertions(+), 76 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldAvailability.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldCriterionFactory.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldKind.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRole.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRoles.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldAvailableForAdmins.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldBooleanCriterionFactory.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldDateCriterionFactory.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonRolesTranslator.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/DetailedSearchFieldComboModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/DetailedSearchFieldComboModel.java index 07696d8ee86..6db73eb071b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/DetailedSearchFieldComboModel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/DetailedSearchFieldComboModel.java @@ -17,20 +17,31 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.model; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISearchFieldKind; /** Model of combo box used in detailed entity search. */ public class DetailedSearchFieldComboModel extends SimplifiedBaseModelData { private static final long serialVersionUID = 1L; - public DetailedSearchFieldComboModel(String code, DetailedSearchField field) + private static final String KIND = "kind"; + + public DetailedSearchFieldComboModel(String code, DetailedSearchField field, + ISearchFieldKind kind) { set(ModelDataPropertyNames.CODE, code); set(ModelDataPropertyNames.OBJECT, field); + set(KIND, kind); } public DetailedSearchField getField() { return get(ModelDataPropertyNames.OBJECT); } + + public ISearchFieldKind getKind() + { + return get(KIND); + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java index 93e1df39657..83216dc0f15 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java @@ -36,10 +36,11 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericCon import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.DetailedSearchFieldComboModel; import ch.systemsx.cisd.openbis.generic.shared.basic.AttributeSearchFieldKindProvider; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CompareType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IAttributeSearchFieldKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISearchFieldKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; /** @@ -202,43 +203,22 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel */ public DetailedSearchCriterion tryGetValue() { + String selectedValue = valueField.getValue(); + DetailedSearchField selectedField = nameField.tryGetSelectedField(); + ISearchFieldKind selectedKind = nameField.tryGetSelectedKind(); - final String selectedValue = valueField.getValue(); - final DetailedSearchField selectedFieldName = nameField.tryGetSelectedField(); - - if (selectedFieldName != null && StringUtils.isBlank(selectedValue) == false) + if (selectedField != null && StringUtils.isBlank(selectedValue) == false) { - String aCode = selectedFieldName.getAttributeCode(); - - CompareType compareType; - if ("REGISTRATION_DATE_UNTIL".equals(aCode)) - { - compareType = CompareType.LESS_THAN_OR_EQUAL; - } else if ("REGISTRATION_DATE".equals(aCode)) - { - compareType = CompareType.EQUALS; - } else if ("REGISTRATION_DATE_FROM".equals(aCode)) - { - compareType = CompareType.MORE_THAN_OR_EQUAL; - } else if ("MODIFICATION_DATE_UNTIL".equals(aCode)) - { - compareType = CompareType.LESS_THAN_OR_EQUAL; - } else if ("MODIFICATION_DATE".equals(aCode)) + if (selectedKind != null && selectedKind.getCriterionFactory() != null) { - compareType = CompareType.EQUALS; - } else if ("MODIFICATION_DATE_FROM".equals(aCode)) - { - compareType = CompareType.MORE_THAN_OR_EQUAL; + return selectedKind.getCriterionFactory().createCriterion(selectedField, + selectedValue); } else { - return new DetailedSearchCriterion(selectedFieldName, selectedValue); + return new DetailedSearchCriterion(selectedField, selectedValue); } - - return new DetailedSearchCriterion(selectedFieldName, compareType, selectedValue); - } return null; - } public String tryGetDescription() @@ -266,13 +246,15 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel DetailedSearchField field = criterion.getField(); String searchString = criterion.getValue(); String description = ""; + ISearchFieldKind kind = null; + switch (field.getKind()) { case ATTRIBUTE: - description = + kind = AttributeSearchFieldKindProvider.getAttributeFieldKind( - nameField.getEntityKind(), field.getAttributeCode()) - .getDescription(); + nameField.getEntityKind(), field.getAttributeCode()); + description = ((IAttributeSearchFieldKind) kind).getDescription(); break; case PROPERTY: description = field.getPropertyCode(); @@ -288,7 +270,8 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel break; } - DetailedSearchFieldComboModel model = new DetailedSearchFieldComboModel(description, field); + DetailedSearchFieldComboModel model = + new DetailedSearchFieldComboModel(description, field, kind); nameField.setValue(model); valueField.setValue(searchString); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java index bbcf609f019..146bfda22aa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.search import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import com.extjs.gxt.ui.client.store.ListStore; @@ -42,6 +43,10 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchFieldKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IAttributeSearchFieldKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISearchFieldAvailability; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISearchFieldKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonRoles; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRowWithObject; @@ -117,6 +122,12 @@ public final class DetailedSearchFieldsSelectionWidget extends return GWTUtils.tryGetSingleSelectedCode(this); } + public ISearchFieldKind tryGetSelectedKind() + { + DetailedSearchFieldComboModel model = GWTUtils.tryGetSingleSelectedModel(this); + return model != null ? model.getKind() : null; + } + // NOTE: should be removed. See the todo for the whole class. public List<PropertyType> getAvailablePropertyTypes() { @@ -146,7 +157,8 @@ public final class DetailedSearchFieldsSelectionWidget extends @Override protected void process(final TypedTableResultSet<PropertyType> result) { - List<TableModelRowWithObject<PropertyType>> rows = result.getResultSet().getList().extractOriginalObjects(); + List<TableModelRowWithObject<PropertyType>> rows = + result.getResultSet().getList().extractOriginalObjects(); propertyTypes = new ArrayList<PropertyType>(); for (TableModelRowWithObject<PropertyType> row : rows) { @@ -215,6 +227,20 @@ public final class DetailedSearchFieldsSelectionWidget extends DetailedSearchField anyField = DetailedSearchField.createAnyField(allEntityPropertyCodes); addComplexFieldComboModel(result, anyField); + Iterator<DetailedSearchFieldComboModel> iterator = result.iterator(); + while (iterator.hasNext()) + { + DetailedSearchFieldComboModel field = iterator.next(); + ISearchFieldAvailability availability = + field.getKind() != null ? field.getKind().getAvailability() : null; + + if (availability != null + && availability.isAvailable(getPerson(), getPersonRoles()) == false) + { + iterator.remove(); + } + } + return result; } @@ -241,14 +267,15 @@ public final class DetailedSearchFieldsSelectionWidget extends DetailedSearchField complexField) { assert complexField.getKind() != DetailedSearchFieldKind.ATTRIBUTE : "attribute field not allowed"; - return new DetailedSearchFieldComboModel(getDisplayName(complexField), complexField); + return new DetailedSearchFieldComboModel(getDisplayName(complexField), complexField, null); } private static DetailedSearchFieldComboModel createAttributeFieldComboModel( DetailedSearchField attributeField, IAttributeSearchFieldKind attributeFieldKind) { assert attributeField.getKind() == DetailedSearchFieldKind.ATTRIBUTE : "attribute field required"; - return new DetailedSearchFieldComboModel(getDisplayName(attributeFieldKind), attributeField); + return new DetailedSearchFieldComboModel(getDisplayName(attributeFieldKind), + attributeField, attributeFieldKind); } private List<String> addEntityPropertyTypes(final List<DetailedSearchFieldComboModel> result, @@ -284,7 +311,7 @@ public final class DetailedSearchFieldsSelectionWidget extends String prefix = getDisplayName(searchField); String property = PropertyTypeRenderer.getDisplayName(propertyType, types); String code = prefix + " \'" + property + "\'"; - return new DetailedSearchFieldComboModel(code, searchField); + return new DetailedSearchFieldComboModel(code, searchField, null); } private static String getDisplayName(DetailedSearchField complexField) @@ -316,4 +343,14 @@ public final class DetailedSearchFieldsSelectionWidget extends { return DatabaseModificationKind.any(ObjectKind.PROPERTY_TYPE); } + + private Person getPerson() + { + return viewContext.getModel().getSessionContext().getUser().getUserPersonObject(); + } + + private PersonRoles getPersonRoles() + { + return viewContext.getModel().getSessionContext().getUser().getUserPersonRoles(); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java index 0aef3401bad..27177ade132 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java @@ -347,8 +347,7 @@ public final class GWTUtils * * @returns <code>null</code> if nothing is selected. */ - private final static <T extends ModelData> T tryGetSingleSelectedModel( - final ComboBox<T> comboBox) + public final static <T extends ModelData> T tryGetSingleSelectedModel(final ComboBox<T> comboBox) { assert comboBox != null : "Unspecified combo box."; final List<T> selection = comboBox.getSelection(); @@ -362,20 +361,31 @@ public final class GWTUtils } /** - * Tries to return the selected object code (saved as {@link ModelDataPropertyNames#CODE} in the - * model) from the given {@link ComboBox}. + * Tries to return the selected object property from the given {@link ComboBox}. * * @returns <code>null</code> if nothing is selected. */ - public final static <T extends ModelData, O> String tryGetSingleSelectedCode( - final ComboBox<T> comboBox) + public final static <T extends ModelData, O> O tryGetSingleSelectedProperty( + final ComboBox<T> comboBox, String propertyName) { T selectedModel = GWTUtils.tryGetSingleSelectedModel(comboBox); if (selectedModel == null) { return null; } - return selectedModel.get(ModelDataPropertyNames.CODE); + return selectedModel.get(propertyName); + } + + /** + * Tries to return the selected object code (saved as {@link ModelDataPropertyNames#CODE} in the + * model) from the given {@link ComboBox}. + * + * @returns <code>null</code> if nothing is selected. + */ + public final static <T extends ModelData> String tryGetSingleSelectedCode( + final ComboBox<T> comboBox) + { + return tryGetSingleSelectedProperty(comboBox, ModelDataPropertyNames.CODE); } /** @@ -384,11 +394,9 @@ public final class GWTUtils * * @returns <code>null</code> if nothing is selected. */ - @SuppressWarnings("unchecked") public final static <T extends ModelData, O> O tryGetSingleSelected(final ComboBox<T> comboBox) { - final T selectedModel = tryGetSingleSelectedModel(comboBox); - return (O) (selectedModel != null ? selectedModel.get(ModelDataPropertyNames.OBJECT) : null); + return tryGetSingleSelectedProperty(comboBox, ModelDataPropertyNames.OBJECT); } /** Returns base URL to the index page of the application. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/User.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/User.java index 7110c697c5d..9e709b7b8e0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/User.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/User.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.dto; import com.google.gwt.user.client.rpc.IsSerializable; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonRoles; /** * User information to be shown in Web client. @@ -35,6 +36,8 @@ public final class User implements IsSerializable private Person userPersonObject; + private PersonRoles userPersonRoles; + public User() { } @@ -88,4 +91,15 @@ public final class User implements IsSerializable { this.userPersonObject = userPersonObject; } + + public PersonRoles getUserPersonRoles() + { + return userPersonRoles; + } + + public void setUserPersonRoles(PersonRoles userPersonRoles) + { + this.userPersonRoles = userPersonRoles; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java index 604a30df49f..dce8d743822 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java @@ -316,6 +316,7 @@ public abstract class AbstractClientService implements IClientService, user.setHomeGroupCode(session.tryGetHomeGroupCode()); user.setUserEmail(session.getUserEmail()); user.setUserPersonObject(session.getUserPersonObject()); + user.setUserPersonRoles(session.getUserPersonRoles()); sessionContext.setUser(user); sessionContext.setAnonymous(session.isAnonymous()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/AbstractExternalDataProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/AbstractExternalDataProvider.java index d2953c0945d..ef411b3d1b9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/AbstractExternalDataProvider.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/AbstractExternalDataProvider.java @@ -191,14 +191,15 @@ public abstract class AbstractExternalDataProvider extends FileFormatType fileFormatType = realDataSet.getFileFormatType(); builder.column(FILE_FORMAT_TYPE).addString( fileFormatType == null ? "" : fileFormatType.getCode()); + builder.column(STORAGE_CONFIRMATION).addString( + SimpleYesNoRenderer.render(dataSet.isStorageConfirmation())); } builder.column(PRODUCTION_DATE).addDate(dataSet.getProductionDate()); builder.column(DATA_PRODUCER_CODE).addString(dataSet.getDataProducerCode()); builder.column(DATA_STORE_CODE).addString(dataSet.getDataStore().getCode()); builder.column(PERM_ID).addString(dataSet.getPermId()); builder.column(SHOW_DETAILS_LINK).addString(dataSet.getPermlink()); - builder.column(STORAGE_CONFIRMATION).addString( - SimpleYesNoRenderer.render(dataSet.isStorageConfirmation())); + IColumnGroup columnGroup = builder.columnGroup(PROPERTIES_PREFIX); DataSetType dataSetType = dataSet.getDataSetType(); if (dataSetType != null) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java index 431a947297f..6e7960d05b2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java @@ -89,6 +89,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleSession; import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; import ch.systemsx.cisd.openbis.generic.shared.translator.GridCustomExpressionTranslator.GridCustomColumnTranslator; +import ch.systemsx.cisd.openbis.generic.shared.translator.PersonRolesTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.PersonTranslator; import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils; import ch.systemsx.cisd.openbis.generic.shared.util.ServerUtils; @@ -661,6 +662,8 @@ public abstract class AbstractServer<T> extends AbstractServiceWithLogger<T> imp result.setUserEmail(session.getUserEmail()); result.setAnonymous(session.isAnonymous()); result.setUserPersonObject(PersonTranslator.translate(person)); + result.setUserPersonRoles(PersonRolesTranslator.translate(person.getAllPersonRoles())); + return result; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java index 68a86e208c5..edd31c2ff48 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java @@ -131,6 +131,8 @@ class IndexFieldNameHelper return SearchFieldConstants.PREFIX_ENTITY_TYPE + CODE; case FILE_TYPE: return SearchFieldConstants.PREFIX_FILE_FORMAT_TYPE + CODE; + case STORAGE_CONFIRMATION: + return SearchFieldConstants.STORAGE_CONFIRMATION; case REGISTRATION_DATE: case REGISTRATION_DATE_FROM: case REGISTRATION_DATE_UNTIL: diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java index c354c31e4da..6e47c5b543e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.io.Serializable; + /** * Kinds of fields connected with Data Set attributes that can be used in detailed text queries. * @@ -31,27 +32,48 @@ public enum DataSetAttributeSearchFieldKind implements Serializable, IAttributeS FILE_TYPE("File Type"), - REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION), + STORAGE_CONFIRMATION("Storage confirmed", new SearchFieldAvailableForAdmins(), + new SearchFieldBooleanCriterionFactory()), + + REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), - MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION), + MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION); + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()); private final String description; + private final ISearchFieldAvailability availability; + + private final ISearchFieldCriterionFactory criterionFactory; + private DataSetAttributeSearchFieldKind(String description) + { + this(description, null, null); + } + + private DataSetAttributeSearchFieldKind(String description, + ISearchFieldAvailability availability, ISearchFieldCriterionFactory criterionFactory) { this.description = description; + this.availability = availability; + this.criterionFactory = criterionFactory; } @Override @@ -66,4 +88,16 @@ public enum DataSetAttributeSearchFieldKind implements Serializable, IAttributeS return name(); } + @Override + public ISearchFieldAvailability getAvailability() + { + return availability; + } + + @Override + public ISearchFieldCriterionFactory getCriterionFactory() + { + return criterionFactory; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java index ad6003449b7..8350647a700 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.io.Serializable; + /** * Kinds of fields connected with Experiment attributes that can be used in detailed text queries. * @@ -33,27 +34,45 @@ public enum ExperimentAttributeSearchFieldKind implements Serializable, IAttribu PROJECT_SPACE("Space"), - REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION), + REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), - MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION), + MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION); + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()); private final String description; + private final ISearchFieldAvailability availability; + + private final ISearchFieldCriterionFactory criterionFactory; + private ExperimentAttributeSearchFieldKind(String description) + { + this(description, null, null); + } + + private ExperimentAttributeSearchFieldKind(String description, + ISearchFieldAvailability availability, ISearchFieldCriterionFactory criterionFactory) { this.description = description; + this.availability = availability; + this.criterionFactory = criterionFactory; } @Override @@ -68,4 +87,16 @@ public enum ExperimentAttributeSearchFieldKind implements Serializable, IAttribu return name(); } + @Override + public ISearchFieldAvailability getAvailability() + { + return availability; + } + + @Override + public ISearchFieldCriterionFactory getCriterionFactory() + { + return criterionFactory; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java index 8ba9da25dd3..c91f63c8e3c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java @@ -21,9 +21,10 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; * * @author Piotr Buczek */ -public interface IAttributeSearchFieldKind +public interface IAttributeSearchFieldKind extends ISearchFieldKind { String getCode(); String getDescription(); + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldAvailability.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldAvailability.java new file mode 100644 index 00000000000..082e444482b --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldAvailability.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012 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.shared.basic.dto; + +/** + * @author pkupczyk + */ +public interface ISearchFieldAvailability +{ + + public boolean isAvailable(Person person, PersonRoles personRoles); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldCriterionFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldCriterionFactory.java new file mode 100644 index 00000000000..fc1a08a2827 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldCriterionFactory.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012 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.shared.basic.dto; + + +/** + * @author pkupczyk + */ +public interface ISearchFieldCriterionFactory +{ + + public DetailedSearchCriterion createCriterion(DetailedSearchField field, String value); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldKind.java new file mode 100644 index 00000000000..0e798ae0c81 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ISearchFieldKind.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012 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.shared.basic.dto; + + +/** + * @author pkupczyk + */ +public interface ISearchFieldKind +{ + + ISearchFieldAvailability getAvailability(); + + ISearchFieldCriterionFactory getCriterionFactory(); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java index b7d3e16085b..dee26cc9054 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.io.Serializable; + /** * Kinds of fields connected with Material attributes that can be used in detailed text queries. * @@ -29,27 +30,45 @@ public enum MaterialAttributeSearchFieldKind implements Serializable, IAttribute MATERIAL_TYPE("Material Type"), - REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION), + REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), - MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION), + MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION); + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()); private final String description; + private final ISearchFieldAvailability availability; + + private final ISearchFieldCriterionFactory criterionFactory; + private MaterialAttributeSearchFieldKind(String description) + { + this(description, null, null); + } + + private MaterialAttributeSearchFieldKind(String description, + ISearchFieldAvailability availability, ISearchFieldCriterionFactory criterionFactory) { this.description = description; + this.availability = availability; + this.criterionFactory = criterionFactory; } @Override @@ -64,4 +83,16 @@ public enum MaterialAttributeSearchFieldKind implements Serializable, IAttribute return name(); } + @Override + public ISearchFieldAvailability getAvailability() + { + return availability; + } + + @Override + public ISearchFieldCriterionFactory getCriterionFactory() + { + return criterionFactory; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRole.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRole.java new file mode 100644 index 00000000000..0e89211dd43 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRole.java @@ -0,0 +1,75 @@ +/* + * Copyright 2012 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.shared.basic.dto; + +import java.io.Serializable; + +/** + * @author pkupczyk + */ +public class PersonRole implements Serializable +{ + + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + private RoleWithHierarchy role; + + private DatabaseInstance databaseInstance; + + private Space space; + + // GWT + @SuppressWarnings("unused") + private PersonRole() + { + } + + public PersonRole(RoleWithHierarchy role, DatabaseInstance databaseInstance, Space space) + { + if (role == null) + { + throw new IllegalArgumentException("Role cannot be null"); + } + if (role.isInstanceLevel() && databaseInstance == null) + { + throw new IllegalArgumentException("Database instance cannot be null for instance role"); + } + if (role.isSpaceLevel() && space == null) + { + throw new IllegalArgumentException("Space cannot be null for space role"); + } + this.role = role; + this.databaseInstance = databaseInstance; + this.space = space; + } + + public RoleWithHierarchy getRole() + { + return role; + } + + public DatabaseInstance getDatabaseInstance() + { + return databaseInstance; + } + + public Space getSpace() + { + return space; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRoles.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRoles.java new file mode 100644 index 00000000000..96c826ff4d9 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/PersonRoles.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012 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.shared.basic.dto; + +import java.io.Serializable; +import java.util.List; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy.RoleCode; + +/** + * @author pkupczyk + */ +public class PersonRoles implements Serializable +{ + + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + private List<PersonRole> personRoles; + + // GWT + @SuppressWarnings("unused") + private PersonRoles() + { + } + + public PersonRoles(List<PersonRole> personRoles) + { + if (personRoles == null) + { + throw new IllegalArgumentException("Roles cannot be null"); + } + this.personRoles = personRoles; + } + + public boolean isAdmin() + { + for (PersonRole personRole : personRoles) + { + if (RoleCode.ADMIN.equals(personRole.getRole().getRoleCode())) + { + return true; + } + } + return false; + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java index c087b28fd0d..150f185d21b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.io.Serializable; + /** * Kinds of fields connected with Sample attributes that can be used in detailed text queries. * @@ -31,27 +32,45 @@ public enum SampleAttributeSearchFieldKind implements Serializable, IAttributeSe SPACE("Space"), - REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION), + REGISTRATION_DATE(CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), - MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION), + MODIFICATION_DATE(CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_DESCRIPTION, + null, new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_FROM( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_FROM_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), REGISTRATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION), + CommonAttributeSearchFieldKindDecsriptions.REGISTRATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()), MODIFICATION_DATE_UNTIL( - CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION); + CommonAttributeSearchFieldKindDecsriptions.MODIFICATION_DATE_UNTIL_DESCRIPTION, null, + new SearchFieldDateCriterionFactory()); private final String description; + private final ISearchFieldAvailability availability; + + private final ISearchFieldCriterionFactory criterionFactory; + private SampleAttributeSearchFieldKind(String description) + { + this(description, null, null); + } + + private SampleAttributeSearchFieldKind(String description, + ISearchFieldAvailability availability, ISearchFieldCriterionFactory criterionFactory) { this.description = description; + this.availability = availability; + this.criterionFactory = criterionFactory; } @Override @@ -66,4 +85,16 @@ public enum SampleAttributeSearchFieldKind implements Serializable, IAttributeSe return name(); } + @Override + public ISearchFieldAvailability getAvailability() + { + return availability; + } + + @Override + public ISearchFieldCriterionFactory getCriterionFactory() + { + return criterionFactory; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldAvailableForAdmins.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldAvailableForAdmins.java new file mode 100644 index 00000000000..137458b6b8b --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldAvailableForAdmins.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012 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.shared.basic.dto; + +/** + * @author pkupczyk + */ +public class SearchFieldAvailableForAdmins implements ISearchFieldAvailability +{ + + @Override + public boolean isAvailable(Person person, PersonRoles personRoles) + { + return personRoles.isAdmin(); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldBooleanCriterionFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldBooleanCriterionFactory.java new file mode 100644 index 00000000000..a4169059816 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldBooleanCriterionFactory.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012 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.shared.basic.dto; + + +/** + * @author pkupczyk + */ +public class SearchFieldBooleanCriterionFactory implements ISearchFieldCriterionFactory +{ + + @Override + public DetailedSearchCriterion createCriterion(DetailedSearchField field, String value) + { + if ("TRUE".equalsIgnoreCase(value) || "YES".equalsIgnoreCase(value)) + { + return new DetailedSearchCriterion(field, "true"); + } else if ("FALSE".equalsIgnoreCase(value) || "NO".equalsIgnoreCase(value)) + { + return new DetailedSearchCriterion(field, "false"); + } else + { + return null; + } + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldDateCriterionFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldDateCriterionFactory.java new file mode 100644 index 00000000000..a02493ee12a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SearchFieldDateCriterionFactory.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012 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.shared.basic.dto; + + +/** + * @author pkupczyk + */ +public class SearchFieldDateCriterionFactory implements ISearchFieldCriterionFactory +{ + + @Override + public DetailedSearchCriterion createCriterion(DetailedSearchField field, String value) + { + String code = field.getAttributeCode(); + CompareType compareType; + + if ("REGISTRATION_DATE_UNTIL".equals(code)) + { + compareType = CompareType.LESS_THAN_OR_EQUAL; + } else if ("REGISTRATION_DATE".equals(code)) + { + compareType = CompareType.EQUALS; + } else if ("REGISTRATION_DATE_FROM".equals(code)) + { + compareType = CompareType.MORE_THAN_OR_EQUAL; + } else if ("MODIFICATION_DATE_UNTIL".equals(code)) + { + compareType = CompareType.LESS_THAN_OR_EQUAL; + } else if ("MODIFICATION_DATE".equals(code)) + { + compareType = CompareType.EQUALS; + } else if ("MODIFICATION_DATE_FROM".equals(code)) + { + compareType = CompareType.MORE_THAN_OR_EQUAL; + } else + { + throw new IllegalArgumentException("Unknown date search field: " + code); + } + + return new DetailedSearchCriterion(field, compareType, value); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExternalDataPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExternalDataPE.java index c78cb671510..8b12f78950c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExternalDataPE.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/ExternalDataPE.java @@ -29,8 +29,11 @@ import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import org.hibernate.search.annotations.Field; +import org.hibernate.search.annotations.Index; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; +import org.hibernate.search.annotations.Store; import org.hibernate.validator.constraints.Length; import ch.systemsx.cisd.common.types.BooleanOrUnknown; @@ -229,6 +232,7 @@ public final class ExternalDataPE extends DataPE } @Column(name = ColumnNames.STORAGE_CONFIRMATION) + @Field(name = SearchFieldConstants.STORAGE_CONFIRMATION, index = Index.UN_TOKENIZED, store = Store.YES) public boolean isStorageConfirmation() { return storageConfirmation; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SessionContextDTO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SessionContextDTO.java index c523ba6d688..ee2e8d3e70b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SessionContextDTO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SessionContextDTO.java @@ -21,6 +21,7 @@ import java.io.Serializable; import ch.systemsx.cisd.openbis.generic.shared.IServer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonRoles; /** * An extract from the Session object, used internally on the server side. @@ -47,6 +48,8 @@ public class SessionContextDTO implements Serializable private Person userPersonObject; + private PersonRoles userPersonRoles; + public void setSessionToken(String sessionToken) { this.sessionToken = sessionToken; @@ -126,4 +129,14 @@ public class SessionContextDTO implements Serializable { return userPersonObject; } + + public void setUserPersonRoles(PersonRoles userPersonRoles) + { + this.userPersonRoles = userPersonRoles; + } + + public PersonRoles getUserPersonRoles() + { + return userPersonRoles; + } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/hibernate/SearchFieldConstants.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/hibernate/SearchFieldConstants.java index 2dd6f9d3484..22f42bd4fc2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/hibernate/SearchFieldConstants.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/hibernate/SearchFieldConstants.java @@ -89,6 +89,8 @@ public final class SearchFieldConstants public static final String FILE_DESCRIPTION = "description"; + public static final String STORAGE_CONFIRMATION = "storage_confirmed"; + public static final String REGISTRATION_DATE = "registration_date"; public static final String MODIFICATION_DATE = "modification_date"; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonRolesTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonRolesTranslator.java new file mode 100644 index 00000000000..65a08e294ef --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PersonRolesTranslator.java @@ -0,0 +1,87 @@ +/* + * Copyright 2012 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.shared.translator; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonRole; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PersonRoles; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy.RoleLevel; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; +import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; + +/** + * @author pkupczyk + */ +public class PersonRolesTranslator +{ + + private PersonRolesTranslator() + { + // Can not be instantiated. + } + + public final static PersonRoles translate(final Collection<RoleAssignmentPE> roleAssignments) + { + final List<PersonRole> personRoles = new ArrayList<PersonRole>(); + + if (roleAssignments != null) + { + for (final RoleAssignmentPE roleAssignment : roleAssignments) + { + PersonRole personRole = translate(roleAssignment); + if (personRole != null) + { + personRoles.add(personRole); + } + } + } + + return new PersonRoles(personRoles); + } + + private final static PersonRole translate(final RoleAssignmentPE roleAssignment) + { + if (roleAssignment == null) + { + return null; + } + + RoleWithHierarchy role; + + if (roleAssignment.getDatabaseInstance() != null) + { + role = RoleWithHierarchy.valueOf(RoleLevel.INSTANCE, roleAssignment.getRole()); + } else if (roleAssignment.getSpace() != null) + { + role = RoleWithHierarchy.valueOf(RoleLevel.SPACE, roleAssignment.getRole()); + } else + { + throw new IllegalArgumentException("Database instance and space cannot be both null"); + } + + DatabaseInstance databaseInstance = + DatabaseInstanceTranslator.translate(roleAssignment.getDatabaseInstance()); + Space space = SpaceTranslator.translate(roleAssignment.getSpace()); + + return new PersonRole(role, databaseInstance, space); + } +} -- GitLab