diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/method/AbstractSearchMethodExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/method/AbstractSearchMethodExecutor.java index 170ca882d58d24bc7a5d1f5903abe9f0dda7e7a7..3e029a2c2dabff078b1f47796a2adf6a52c1a314 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/method/AbstractSearchMethodExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/method/AbstractSearchMethodExecutor.java @@ -31,11 +31,11 @@ import ch.ethz.sis.openbis.generic.server.api.v3.cache.SearchCacheEntry; import ch.ethz.sis.openbis.generic.server.api.v3.cache.SearchCacheKey; import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.ISearchObjectExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.sort.SortAndPage; import ch.ethz.sis.openbis.generic.server.api.v3.translator.ITranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.CacheMode; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.FetchOptions; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortAndPage; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.AbstractObjectSearchCriteria; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.SearchResult; import ch.systemsx.cisd.common.logging.LogCategory; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/AbstractComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/AbstractComparator.java similarity index 94% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/AbstractComparator.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/AbstractComparator.java index 23a9b7ea07925cb55437b25cb9913696194d84b7..6cbd8d169ac9750aac7ab6008c1a83aa28a2ded5 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/AbstractComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/AbstractComparator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import java.util.Comparator; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/AbstractStringComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/AbstractStringComparator.java similarity index 92% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/AbstractStringComparator.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/AbstractStringComparator.java index 6b2f2d5cf1df599e0585ef82cc746b2599847b44..a247754147fc4b4648324640bd0059273d2748ca 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/AbstractStringComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/AbstractStringComparator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import ch.systemsx.cisd.common.collection.AlphanumComparator; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/CodeComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/CodeComparator.java similarity index 87% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/CodeComparator.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/CodeComparator.java index 2791277619e5f888bc7751377156201df9f12126..1980bc1bab8665684c2d937b192f825e09392761 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/CodeComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/CodeComparator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.ICodeHolder; @@ -24,8 +24,6 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.ICodeHold public class CodeComparator<OBJECT extends ICodeHolder> extends AbstractStringComparator<OBJECT> { - public static final String CODE = "CODE"; - @Override protected String getValue(ICodeHolder o) { diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/ComparatorFactory.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/ComparatorFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..492d1211a8782576805b70d85004be1131394475 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/ComparatorFactory.java @@ -0,0 +1,58 @@ +/* + * Copyright 2015 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.ethz.sis.openbis.generic.server.api.v3.helper.sort; + +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.helper.tag.TagComparatorFactory; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOptions; + +/** + * @author pkupczyk + */ +@SuppressWarnings("rawtypes") +public abstract class ComparatorFactory +{ + + private static List<ComparatorFactory> factories = new LinkedList<ComparatorFactory>(); + + static + { + factories.add(new TagComparatorFactory()); + factories.add(new EntityWithPropertiesComparatorFactory()); + factories.add(new EntityComparatorFactory()); + } + + public abstract boolean accepts(SortOptions<?> sortOptions); + + public abstract Comparator getComparator(String field); + + public static ComparatorFactory getInstance(SortOptions<?> sortOptions) + { + for (ComparatorFactory factory : factories) + { + if (factory.accepts(sortOptions)) + { + return factory; + } + } + + throw new IllegalArgumentException("Comparator factory for sort options " + sortOptions.getClass() + " not found"); + } +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/EntityComparatorFactory.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/EntityComparatorFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..b2704aafd6aa4c3dda25d4111edb7662e4e60983 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/EntityComparatorFactory.java @@ -0,0 +1,58 @@ +/* + * Copyright 2015 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.ethz.sis.openbis.generic.server.api.v3.helper.sort; + +import java.util.Comparator; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.ICodeHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModificationDateHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IRegistrationDateHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.EntitySortOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOptions; + +/** + * @author pkupczyk + */ +public class EntityComparatorFactory<OBJECT extends ICodeHolder & IRegistrationDateHolder & IModificationDateHolder> extends + ComparatorFactory +{ + + @Override + public boolean accepts(SortOptions<?> sortOptions) + { + return sortOptions instanceof EntitySortOptions; + } + + @Override + public Comparator<OBJECT> getComparator(String field) + { + if (EntitySortOptions.CODE.equals(field)) + { + return new CodeComparator<OBJECT>(); + } else if (EntitySortOptions.REGISTRATION_DATE.equals(field)) + { + return new RegistrationDateComparator<OBJECT>(); + } else if (EntitySortOptions.MODIFICATION_DATE.equals(field)) + { + return new ModificationDateComparator<OBJECT>(); + } else + { + return null; + } + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/EntityWithPropertiesComparatorFactory.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/EntityWithPropertiesComparatorFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..104e10fdf90008e06f5f4227d0446f467467df1e --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/EntityWithPropertiesComparatorFactory.java @@ -0,0 +1,53 @@ +/* + * Copyright 2015 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.ethz.sis.openbis.generic.server.api.v3.helper.sort; + +import java.util.Comparator; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.ICodeHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModificationDateHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IPropertiesHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IRegistrationDateHolder; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.EntityWithPropertiesSortOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOptions; + +/** + * @author pkupczyk + */ +public class EntityWithPropertiesComparatorFactory<OBJECT extends ICodeHolder & IRegistrationDateHolder & IModificationDateHolder & IPropertiesHolder> + extends EntityComparatorFactory<OBJECT> +{ + + @Override + public boolean accepts(SortOptions<?> sortOptions) + { + return sortOptions instanceof EntityWithPropertiesSortOptions; + } + + @Override + public Comparator<OBJECT> getComparator(String field) + { + if (field.startsWith(EntityWithPropertiesSortOptions.PROPERTY)) + { + return new PropertyComparator<OBJECT>(field.substring(EntityWithPropertiesSortOptions.PROPERTY.length())); + } else + { + return super.getComparator(field); + } + } + +} diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/ModificationDateComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/ModificationDateComparator.java similarity index 86% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/ModificationDateComparator.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/ModificationDateComparator.java index 0ca8a07eebc5424925a7006fb94950001490829e..40e41879065f74118cb0899a4d087524d23e577e 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/ModificationDateComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/ModificationDateComparator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import java.util.Date; @@ -26,8 +26,6 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModifica public class ModificationDateComparator<OBJECT extends IModificationDateHolder> extends AbstractComparator<OBJECT, Date> { - public static final String MODIFICATION_DATE = "MODIFICATION_DATE"; - @Override protected Date getValue(IModificationDateHolder o) { diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/PropertyComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/PropertyComparator.java similarity index 88% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/PropertyComparator.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/PropertyComparator.java index 84f12509c30b88d115476af5b9b91bf89f919033..9b44b737e5bd6151dd3f13141de9dd5ed1c4ce40 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/PropertyComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/PropertyComparator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IPropertiesHolder; @@ -24,8 +24,6 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IProperti public class PropertyComparator<OBJECT extends IPropertiesHolder> extends AbstractStringComparator<OBJECT> { - public static final String PROPERTY = "PROPERTY"; - private String propertyName; public PropertyComparator(String propertyName) diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/RegistrationDateComparator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/RegistrationDateComparator.java similarity index 86% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/RegistrationDateComparator.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/RegistrationDateComparator.java index efc8ad5c8c0c966b92f97d59c2e5562ee4ac00fd..4d57c20e9b8308f5a6e1e09dbf18708e9617adb1 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/comparator/RegistrationDateComparator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/RegistrationDateComparator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import java.util.Date; @@ -26,8 +26,6 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IRegistra public class RegistrationDateComparator<OBJECT extends IRegistrationDateHolder> extends AbstractComparator<OBJECT, Date> { - public static final String REGISTRATION_DATE = "REGISTRATION_DATE"; - @Override protected Date getValue(IRegistrationDateHolder o) { diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortAndPage.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/SortAndPage.java similarity index 97% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortAndPage.java rename to openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/SortAndPage.java index 8bb07cd91eb312fbdf805e11b51f31472841d542..3d50bb7500ec90f6f7195a08945557d13eec542d 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortAndPage.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/SortAndPage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; @@ -32,6 +32,8 @@ import java.util.Set; import org.springframework.beans.BeanUtils; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.FetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.Sorting; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.view.AbstractCollectionView; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.view.ListView; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.view.SetView; @@ -218,7 +220,8 @@ public class SortAndPage { if (sorting.getField() != null) { - Comparator aComparator = sortBy.getComparator(sorting.getField()); + Comparator aComparator = ComparatorFactory.getInstance(sortBy).getComparator(sorting.getField()); + if (aComparator == null) { throw new IllegalArgumentException("Comparator for field " + sorting.getField() + " not found"); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/tag/TagComparatorFactory.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/tag/TagComparatorFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..390da594629a4dc3328f157744a420606f863dd8 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/tag/TagComparatorFactory.java @@ -0,0 +1,55 @@ +/* + * Copyright 2015 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.ethz.sis.openbis.generic.server.api.v3.helper.tag; + +import java.util.Comparator; + +import ch.ethz.sis.openbis.generic.server.api.v3.helper.sort.CodeComparator; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.sort.ComparatorFactory; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.sort.RegistrationDateComparator; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.tag.Tag; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.tag.TagSortOptions; + +/** + * @author pkupczyk + */ +public class TagComparatorFactory extends ComparatorFactory +{ + + @Override + public boolean accepts(SortOptions<?> sortOptions) + { + return sortOptions instanceof TagSortOptions; + } + + @Override + public Comparator<Tag> getComparator(String field) + { + if (TagSortOptions.CODE.equals(field)) + { + return new CodeComparator<Tag>(); + } else if (TagSortOptions.REGISTRATION_DATE.equals(field)) + { + return new RegistrationDateComparator<Tag>(); + } else + { + return null; + } + } + +} diff --git a/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortAndPageTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/SortAndPageTest.java similarity index 98% rename from openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortAndPageTest.java rename to openbis/sourceTest/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/SortAndPageTest.java index 344f49e89c4a1398c5b9bd65d2239e0ba335e384..02f6b101fc45f852947452584e18c5ab79623a04 100644 --- a/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortAndPageTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/sort/SortAndPageTest.java @@ -1,6 +1,7 @@ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort; +package ch.ethz.sis.openbis.generic.server.api.v3.helper.sort; import static org.testng.AssertJUnit.assertEquals; + import java.sql.Date; import java.util.ArrayList; import java.util.Arrays; @@ -13,6 +14,7 @@ import java.util.Set; import org.testng.annotations.Test; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.sort.SortAndPage; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.person.Person; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntitySortOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntitySortOptions.java index 04296ab25054cfea03a1d09e85c3794fadf08472..d1efa1ebb459f1f27210e4d7bc1f13127b5ff335 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntitySortOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntitySortOptions.java @@ -16,18 +16,9 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort; -import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.CodeComparator.CODE; -import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.ModificationDateComparator.MODIFICATION_DATE; -import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.RegistrationDateComparator.REGISTRATION_DATE; - -import java.util.Comparator; - import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.ICodeHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModificationDateHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IRegistrationDateHolder; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.CodeComparator; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.ModificationDateComparator; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.RegistrationDateComparator; import ch.systemsx.cisd.base.annotation.JsonObject; /** @@ -39,6 +30,12 @@ public class EntitySortOptions<OBJECT extends ICodeHolder & IRegistrationDateHol private static final long serialVersionUID = 1L; + public static final String CODE = "CODE"; + + public static final String MODIFICATION_DATE = "MODIFICATION_DATE"; + + public static final String REGISTRATION_DATE = "REGISTRATION_DATE"; + public SortOrder code() { return getOrCreateSorting(CODE); @@ -69,21 +66,4 @@ public class EntitySortOptions<OBJECT extends ICodeHolder & IRegistrationDateHol return getSorting(MODIFICATION_DATE); } - @Override - public Comparator<OBJECT> getComparator(String field) - { - if (CODE.equals(field)) - { - return new CodeComparator<OBJECT>(); - } else if (REGISTRATION_DATE.equals(field)) - { - return new RegistrationDateComparator<OBJECT>(); - } else if (MODIFICATION_DATE.equals(field)) - { - return new ModificationDateComparator<OBJECT>(); - } else - { - return null; - } - } } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntityWithPropertiesSortOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntityWithPropertiesSortOptions.java index f819b2ab60ddf71eee675885ffced294060745f7..5fb28e384ca73f8aaca4eb381e7d0fbd109f5468 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntityWithPropertiesSortOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/EntityWithPropertiesSortOptions.java @@ -16,15 +16,10 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort; -import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.PropertyComparator.PROPERTY; - -import java.util.Comparator; - import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.ICodeHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModificationDateHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IPropertiesHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IRegistrationDateHolder; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.PropertyComparator; import ch.systemsx.cisd.base.annotation.JsonObject; /** @@ -37,6 +32,8 @@ public class EntityWithPropertiesSortOptions<OBJECT extends ICodeHolder & IRegis private static final long serialVersionUID = 1L; + public static final String PROPERTY = "PROPERTY"; + public SortOrder property(String propertyName) { return getOrCreateSorting(PROPERTY + propertyName); @@ -47,15 +44,4 @@ public class EntityWithPropertiesSortOptions<OBJECT extends ICodeHolder & IRegis return getSorting(PROPERTY + propertyName); } - @Override - public Comparator<OBJECT> getComparator(String field) - { - if (field.startsWith(PROPERTY)) - { - return new PropertyComparator<OBJECT>(field.substring(PROPERTY.length())); - } else - { - return super.getComparator(field); - } - } } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortOptions.java index 3ed31b2e4e598b857f680b9905d2113797d308dc..3bc34e365d816d6937d9a68b92f0b60204565316 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/sort/SortOptions.java @@ -17,7 +17,6 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort; import java.io.Serializable; -import java.util.Comparator; import java.util.LinkedList; import java.util.List; @@ -34,11 +33,6 @@ public abstract class SortOptions<OBJECT> implements Serializable private List<Sorting> sortings = new LinkedList<>(); - public Comparator<OBJECT> getComparator(String field) - { - return null; - } - protected SortOrder getOrCreateSorting(String field) { SortOrder order = getSorting(field); diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/tag/TagSortOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/tag/TagSortOptions.java index d2ede6f23cff7ef2dedf6bd5e1445179c9b01fe4..41408647a4d977e9bc2b761af44093a3d3e91e19 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/tag/TagSortOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/tag/TagSortOptions.java @@ -16,16 +16,9 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.tag; -import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.CodeComparator.CODE; -import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.RegistrationDateComparator.REGISTRATION_DATE; - -import java.util.Comparator; - import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.tag.Tag; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.SortOrder; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.CodeComparator; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.RegistrationDateComparator; import ch.systemsx.cisd.base.annotation.JsonObject; /** @@ -37,6 +30,10 @@ public class TagSortOptions extends SortOptions<Tag> private static final long serialVersionUID = 1L; + public static final String CODE = "CODE"; + + public static final String REGISTRATION_DATE = "REGISTRATION_DATE"; + public SortOrder code() { return getOrCreateSorting(CODE); @@ -57,18 +54,4 @@ public class TagSortOptions extends SortOptions<Tag> return getSorting(REGISTRATION_DATE); } - @Override - public Comparator<Tag> getComparator(String field) - { - if (CODE.equals(field)) - { - return new CodeComparator<Tag>(); - } else if (REGISTRATION_DATE.equals(field)) - { - return new RegistrationDateComparator<Tag>(); - } else - { - return null; - } - } }