Skip to content
Snippets Groups Projects
Commit c4ddd3ad authored by vkovtun's avatar vkovtun
Browse files

SSDM-9845 Added searching by registration and modifier (user ID) in any field search.

parent b068841f
No related branches found
No related tags found
No related merge requests found
......@@ -36,60 +36,75 @@ public enum TableMapper
{
SAMPLE(SAMPLES_VIEW, SAMPLE_TYPE_COLUMN, PROPERTY_TYPES_TABLE, DATA_TYPE_COLUMN, SAMPLE_TYPES_TABLE,
SAMPLE_TYPE_PROPERTY_TYPE_TABLE, SAMPLE_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, SAMPLE_PROPERTIES_TABLE, SAMPLE_COLUMN,
SAMPLE_TYPE_PROPERTY_TYPE_COLUMN, SAMPLE_RELATIONSHIPS_VIEW, PARENT_SAMPLE_COLUMN, CHILD_SAMPLE_COLUMN, DATA_VIEW,
SAMPLE_COLUMN, SAMPLE_COLUMN, EntityKind.SAMPLE),
SAMPLE_TYPE_PROPERTY_TYPE_TABLE, SAMPLE_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, SAMPLE_PROPERTIES_TABLE,
SAMPLE_COLUMN, SAMPLE_TYPE_PROPERTY_TYPE_COLUMN, SAMPLE_RELATIONSHIPS_VIEW, PARENT_SAMPLE_COLUMN,
CHILD_SAMPLE_COLUMN, DATA_VIEW, SAMPLE_COLUMN, SAMPLE_COLUMN, EntityKind.SAMPLE, true, true),
SAMPLE_TYPE(SAMPLE_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, EntityKind.SAMPLE),
null, null, null, null, EntityKind.SAMPLE, false, false),
EXPERIMENT(EXPERIMENTS_VIEW, EXPERIMENT_TYPE_COLUMN, PROPERTY_TYPES_TABLE, DATA_TYPE_COLUMN, EXPERIMENT_TYPES_TABLE,
EXPERIMENT_TYPE_PROPERTY_TYPE_TABLE, EXPERIMENT_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, EXPERIMENT_PROPERTIES_TABLE, EXPERIMENT_COLUMN,
EXPERIMENT_TYPE_PROPERTY_TYPE_COLUMN, null, null, null, DATA_VIEW, EXPERIMENT_COLUMN, EXPERIMENT_COLUMN, EntityKind.EXPERIMENT),
EXPERIMENT_TYPE_PROPERTY_TYPE_TABLE, EXPERIMENT_TYPE_COLUMN, PROPERTY_TYPE_COLUMN,
EXPERIMENT_PROPERTIES_TABLE, EXPERIMENT_COLUMN, EXPERIMENT_TYPE_PROPERTY_TYPE_COLUMN, null, null, null,
DATA_VIEW, EXPERIMENT_COLUMN, EXPERIMENT_COLUMN, EntityKind.EXPERIMENT, true, true),
EXPERIMENT_TYPE(EXPERIMENT_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
EntityKind.EXPERIMENT),
EXPERIMENT_TYPE(EXPERIMENT_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, EntityKind.EXPERIMENT, false, false),
DATA_SET(DATA_VIEW, DATA_SET_TYPE_COLUMN, PROPERTY_TYPES_TABLE, DATA_TYPE_COLUMN, DATA_SET_TYPES_TABLE, DATA_SET_TYPE_PROPERTY_TYPE_TABLE,
DATA_SET_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, DATA_SET_PROPERTIES_TABLE, DATA_SET_COLUMN, DATA_SET_TYPE_PROPERTY_TYPE_COLUMN,
DATA_SET_RELATIONSHIPS_VIEW, DATA_PARENT_COLUMN, DATA_CHILD_COLUMN, DATA_VIEW, ID_COLUMN, DATA_ID_COLUMN, EntityKind.DATA_SET),
DATA_SET(DATA_VIEW, DATA_SET_TYPE_COLUMN, PROPERTY_TYPES_TABLE, DATA_TYPE_COLUMN, DATA_SET_TYPES_TABLE,
DATA_SET_TYPE_PROPERTY_TYPE_TABLE, DATA_SET_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, DATA_SET_PROPERTIES_TABLE,
DATA_SET_COLUMN, DATA_SET_TYPE_PROPERTY_TYPE_COLUMN, DATA_SET_RELATIONSHIPS_VIEW, DATA_PARENT_COLUMN,
DATA_CHILD_COLUMN, DATA_VIEW, ID_COLUMN, DATA_ID_COLUMN, EntityKind.DATA_SET, true, true),
DATA_SET_TYPE(DATA_SET_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
EntityKind.DATA_SET),
DATA_SET_TYPE(DATA_SET_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, EntityKind.DATA_SET, false, false),
MATERIAL(MATERIALS_TABLE, MATERIAL_TYPE_COLUMN, PROPERTY_TYPES_TABLE, DATA_TYPE_COLUMN, MATERIAL_TYPES_TABLE,
MATERIAL_TYPE_PROPERTY_TYPE_TABLE, MATERIAL_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, MATERIAL_PROPERTIES_TABLE, MATERIAL_COLUMN,
MATERIAL_TYPE_PROPERTY_TYPE_COLUMN, null, null, null, DATA_VIEW, MATERIAL_COLUMN, MATERIAL_COLUMN, EntityKind.MATERIAL),
MATERIAL_TYPE_PROPERTY_TYPE_TABLE, MATERIAL_TYPE_COLUMN, PROPERTY_TYPE_COLUMN, MATERIAL_PROPERTIES_TABLE,
MATERIAL_COLUMN, MATERIAL_TYPE_PROPERTY_TYPE_COLUMN, null, null, null, DATA_VIEW, MATERIAL_COLUMN,
MATERIAL_COLUMN, EntityKind.MATERIAL, true, false),
MATERIAL_TYPE(MATERIAL_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
EntityKind.MATERIAL),
MATERIAL_TYPE(MATERIAL_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, EntityKind.MATERIAL, false, false),
PERSON(PERSONS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
PERSON(PERSONS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, true, false),
PROJECT(PROJECTS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
PROJECT(PROJECTS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, true, true),
SPACE(SPACES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
SPACE(SPACES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, true, false),
TAG(METAPROJECTS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
TAG(METAPROJECTS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, false, false),
SEMANTIC_ANNOTATION(SEMANTIC_ANNOTATIONS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
SEMANTIC_ANNOTATION(SEMANTIC_ANNOTATIONS_TABLE, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, false, false),
PROPERTY_TYPE(PROPERTY_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
PROPERTY_TYPE(PROPERTY_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, true, false),
SAMPLE_PROPERTY_ASSIGNMENT(SAMPLE_TYPE_PROPERTY_TYPE_TABLE, null, null, null, null, null, SAMPLE_TYPE_COLUMN, null, null, null, null, null, null, null, null,
null, null, EntityKind.SAMPLE),
SAMPLE_PROPERTY_ASSIGNMENT(SAMPLE_TYPE_PROPERTY_TYPE_TABLE, null, null, null, null, null, SAMPLE_TYPE_COLUMN, null,
null, null, null, null, null, null, null, null, null, EntityKind.SAMPLE, true, false),
CONTENT_COPIES(CONTENT_COPIES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
CONTENT_COPIES(CONTENT_COPIES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, true, false),
EXTERNAL_DATA(EXTERNAL_DATA_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
EXTERNAL_DATA(EXTERNAL_DATA_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, false, false),
EXTERNAL_DMS(EXTERNAL_DATA_MANAGEMENT_SYSTEMS_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
EXTERNAL_DMS(EXTERNAL_DATA_MANAGEMENT_SYSTEMS_TABLE, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, false, false),
FILE_FORMAT_TYPES(FILE_FORMAT_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
FILE_FORMAT_TYPES(FILE_FORMAT_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, false, false),
LOCATOR_TYPES(LOCATOR_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
LOCATOR_TYPES(LOCATOR_TYPES_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, false, false),
CONTROLLED_VOCABULARY_TERMS(CONTROLLED_VOCABULARY_TERM_TABLE, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
CONTROLLED_VOCABULARY_TERMS(CONTROLLED_VOCABULARY_TERM_TABLE, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, true, false);
static
{
......@@ -189,12 +204,18 @@ public enum TableMapper
private Map<PSQLTypes, Set<String>> sqlTypeToFieldsMap = new HashMap<>();
private final boolean withRegistrator;
private final boolean withModifier;
TableMapper(final String entitiesTable, final String entitiesTableEntityTypeIdField, final String attributeTypesTable,
final String attributeTypesTableDataTypeIdField, final String entityTypesTable, final String entityTypesAttributeTypesTable,
final String entityTypesAttributeTypesTableEntityTypeIdField, final String entityTypesAttributeTypesTableAttributeTypeIdField,
final String valuesTable, final String valuesTableEntityIdField, final String valuesTableEntityTypeAttributeTypeIdField,
final String relationshipsTable, final String relationshipsTableParentIdField, final String relationshipsTableChildIdField,
final String dataTable, final String dataTableEntityIdField, final String metaprojectAssignmentsEntityIdField, final EntityKind entityKind)
final String dataTable, final String dataTableEntityIdField,
final String metaprojectAssignmentsEntityIdField, final EntityKind entityKind, final boolean withRegistrator,
final boolean withModifier)
{
this.entitiesTable = entitiesTable;
this.entitiesTableEntityTypeIdField = entitiesTableEntityTypeIdField;
......@@ -214,6 +235,8 @@ public enum TableMapper
this.dataTableEntityIdField = dataTableEntityIdField;
this.metaprojectAssignmentsEntityIdField = metaprojectAssignmentsEntityIdField;
this.entityKind = entityKind;
this.withRegistrator = withRegistrator;
this.withModifier = withModifier;
}
public static TableMapper toEntityMapper(final EntityKind entityKind, final boolean isEntityType)
......@@ -316,6 +339,16 @@ public enum TableMapper
return entityKind;
}
public boolean hasRegistrator()
{
return withRegistrator;
}
public boolean hasModifier()
{
return withModifier;
}
private static void initSampleFieldToSQLTypeMap()
{
final Map<String, PSQLTypes> fields = SAMPLE.fieldToSQLTypeMap;
......
......@@ -16,11 +16,6 @@
package ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.condition;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.AbstractStringValue;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.AnyFieldSearchCriteria;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.StringEqualToValue;
......@@ -34,34 +29,59 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
import ch.systemsx.cisd.openbis.generic.shared.util.SimplePropertyValidator;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.BOOLEAN;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.FLOAT4;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.FLOAT8;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.INT2;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.INT4;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.INT8;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.TIMESTAMP_WITH_TZ;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.VARCHAR;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.DOUBLE_COLON;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.EQ;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.FALSE;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.NL;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.OR;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.PERIOD;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.QU;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.SP;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.PSQLTypes.*;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SQLLexemes.*;
import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.SearchCriteriaTranslator.MAIN_TABLE_ALIAS;
import static ch.systemsx.cisd.openbis.generic.shared.dto.ColumnNames.*;
import static ch.systemsx.cisd.openbis.generic.shared.dto.TableNames.PERSONS_TABLE;
public class AnyFieldSearchConditionTranslator implements IConditionTranslator<AnyFieldSearchCriteria>
{
private static final String UNIQUE_PREFIX = AnyFieldSearchConditionTranslator.class.getName();
private static final String REGISTRATOR_JOIN_INFORMATION_KEY = "registrator";
private static final String MODIFIER_JOIN_INFORMATION_KEY = "modifier";
@Override
public Map<String, JoinInformation> getJoinInformationMap(final AnyFieldSearchCriteria criterion, final TableMapper tableMapper,
final IAliasFactory aliasFactory)
{
final Map<String, JoinInformation> result = TranslatorUtils.getPropertyJoinInformationMap(tableMapper, aliasFactory, JoinType.LEFT);
TranslatorUtils.appendIdentifierJoinInformationMap(result, tableMapper, aliasFactory, UNIQUE_PREFIX);
if (tableMapper.hasRegistrator())
{
final JoinInformation registratorJoinInformation = new JoinInformation();
registratorJoinInformation.setJoinType(JoinType.INNER);
registratorJoinInformation.setMainTable(tableMapper.getEntitiesTable());
registratorJoinInformation.setMainTableAlias(MAIN_TABLE_ALIAS);
registratorJoinInformation.setMainTableIdField(PERSON_REGISTERER_COLUMN);
registratorJoinInformation.setSubTable(PERSONS_TABLE);
registratorJoinInformation.setSubTableAlias(aliasFactory.createAlias());
registratorJoinInformation.setSubTableIdField(ID_COLUMN);
result.put(REGISTRATOR_JOIN_INFORMATION_KEY, registratorJoinInformation);
}
if (tableMapper.hasModifier())
{
final JoinInformation registratorJoinInformation = new JoinInformation();
registratorJoinInformation.setJoinType(JoinType.LEFT);
registratorJoinInformation.setMainTable(tableMapper.getEntitiesTable());
registratorJoinInformation.setMainTableAlias(MAIN_TABLE_ALIAS);
registratorJoinInformation.setMainTableIdField(PERSON_MODIFIER_COLUMN);
registratorJoinInformation.setSubTable(PERSONS_TABLE);
registratorJoinInformation.setSubTableAlias(aliasFactory.createAlias());
registratorJoinInformation.setSubTableIdField(ID_COLUMN);
result.put(MODIFIER_JOIN_INFORMATION_KEY, registratorJoinInformation);
}
return result;
}
......@@ -88,6 +108,24 @@ public class AnyFieldSearchConditionTranslator implements IConditionTranslator<A
IdentifierSearchConditionTranslator.doTranslate(criterion, tableMapper, args, sqlBuilder, aliases, UNIQUE_PREFIX);
sqlBuilder.append(separator);
if (tableMapper.hasRegistrator())
{
sqlBuilder.append(aliases.get(REGISTRATOR_JOIN_INFORMATION_KEY).getSubTableAlias()).append(PERIOD)
.append(USER_COLUMN).append(SP);
TranslatorUtils.appendStringComparatorOp(value.getClass(),
TranslatorUtils.stripQuotationMarks(value.getValue()), sqlBuilder, args);
sqlBuilder.append(separator);
}
if (tableMapper.hasModifier())
{
sqlBuilder.append(aliases.get(MODIFIER_JOIN_INFORMATION_KEY).getSubTableAlias()).append(PERIOD)
.append(USER_COLUMN).append(SP);
TranslatorUtils.appendStringComparatorOp(value.getClass(),
TranslatorUtils.stripQuotationMarks(value.getValue()), sqlBuilder, args);
sqlBuilder.append(separator);
}
final StringBuilder resultSqlBuilder = tableMapper.getFieldToSQLTypeMap().entrySet().stream().collect(
StringBuilder::new,
(stringBuilder, fieldToSQLTypesEntry) ->
......
......@@ -1003,6 +1003,22 @@ public class SearchSampleTest extends AbstractSampleTest
testSearch(TEST_USER, criteria, "/CISD/CP-TEST-1");
}
@Test
public void testSearchWithAnyFieldMatchingRegistratorsUserId()
{
final SampleSearchCriteria criteria = new SampleSearchCriteria();
criteria.withAnyField().thatEquals("etlserver");
testSearch(TEST_USER, criteria, "/CISD/RP1-A2X", "/CISD/RP1-B1X", "/CISD/RP2-A1X");
}
@Test
public void testSearchWithAnyFieldMatchingModifiersUserId()
{
final SampleSearchCriteria criteria = new SampleSearchCriteria();
criteria.withAnyField().thatEquals("test_role");
testSearch(TEST_USER, criteria, "/CISD/CL1", "/CISD/CP-TEST-1", "/TEST-SPACE/FV-TEST");
}
@Test
public void testSearchWithAnyFieldMatchingAttribute()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment