Skip to content
Snippets Groups Projects
Commit e127a136 authored by pkupczyk's avatar pkupczyk
Browse files

SSDM-2636 : V3 AS API - sort search results by property values

SVN: 35020
parent b67595a9
No related branches found
No related tags found
No related merge requests found
/*
* 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.shared.api.v3.dto.fetchoptions.sort.comparator;
import java.util.Map;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IPropertiesHolder;
/**
* @author pkupczyk
*/
public class PropertyComparator<OBJECT> extends AbstractStringComparator<OBJECT>
{
public static final String PROPERTY = "PROPERTY";
private String propertyName;
public PropertyComparator(String propertyName)
{
this.propertyName = propertyName;
}
@Override
protected String getValue(OBJECT o)
{
if (o instanceof IPropertiesHolder)
{
Map<String, String> properties = ((IPropertiesHolder) o).getProperties();
return properties != null ? properties.get(propertyName) : null;
} else
{
throw new IllegalArgumentException("Object " + o + " does not implement " + IPropertiesHolder.class
+ " interface therefore cannot be sorted by a property value.");
}
}
}
...@@ -20,7 +20,6 @@ import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.co ...@@ -20,7 +20,6 @@ import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.co
import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.RegistrationDateComparator.REGISTRATION_DATE; import static ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sort.comparator.RegistrationDateComparator.REGISTRATION_DATE;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.tag.Tag; 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.SortOptions;
...@@ -59,9 +58,17 @@ public class TagSortOptions extends SortOptions<Tag> ...@@ -59,9 +58,17 @@ public class TagSortOptions extends SortOptions<Tag>
} }
@Override @Override
public void addComparators(Map<String, Comparator<Tag>> map) public Comparator<Tag> getComparator(String field)
{ {
map.put(CODE, new CodeComparator<Tag>()); if (CODE.equals(field))
map.put(REGISTRATION_DATE, new RegistrationDateComparator<Tag>()); {
return new CodeComparator<Tag>();
} else if (REGISTRATION_DATE.equals(field))
{
return new RegistrationDateComparator<Tag>();
} else
{
return null;
}
} }
} }
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