Skip to content
Snippets Groups Projects
Commit 05e7467a authored by felmer's avatar felmer
Browse files

SSDM-3401: Java part including system tests implemented.

SVN: 36075
parent bdef3de0
No related branches found
No related tags found
No related merge requests found
Showing
with 658 additions and 13 deletions
......@@ -61,6 +61,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.Project;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.fetchoptions.ProjectFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectIdentifier;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectPermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.Sample;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.SampleType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions.SampleFetchOptions;
......@@ -126,7 +127,6 @@ public class Generator extends AbstractGenerator
// potentially missing fields:
// type.getSampleTypePropertyTypes();
// type.getValidationScript();
DtoGenerator gen = new DtoGenerator("sample", "SampleType", SampleTypeFetchOptions.class);
......@@ -143,6 +143,8 @@ public class Generator extends AbstractGenerator
addModificationDate(gen);
gen.setToStringMethod("\"SampleType \" + code");
gen.addPluralFetchedField("List<PropertyAssignment>", List.class.getName(), "propertyAssignments",
"Property assigments", PropertyAssignmentFetchOptions.class);
return gen;
}
......@@ -212,8 +214,8 @@ public class Generator extends AbstractGenerator
addModificationDate(gen);
gen.setToStringMethod("\"ExperimentType \" + code");
// TODO add property definitions
gen.addPluralFetchedField("List<PropertyAssignment>", List.class.getName(), "propertyAssignments",
"Property assigments", PropertyAssignmentFetchOptions.class);
// TODO add validation script
return gen;
......@@ -275,8 +277,8 @@ public class Generator extends AbstractGenerator
addModificationDate(gen);
gen.setToStringMethod("\"DataSetType \" + code");
// TODO add property definitions
gen.addPluralFetchedField("List<PropertyAssignment>", List.class.getName(), "propertyAssignments",
"Property assigments", PropertyAssignmentFetchOptions.class);
// TODO add validation script
return gen;
......@@ -517,6 +519,8 @@ public class Generator extends AbstractGenerator
addModificationDate(gen);
gen.setToStringMethod("\"MaterialType \" + code");
gen.addPluralFetchedField("List<PropertyAssignment>", List.class.getName(), "propertyAssignments",
"Property assigments", PropertyAssignmentFetchOptions.class);
return gen;
}
......
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.helper.property;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentSortOptions;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.AbstractStringComparator;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.ComparatorFactory;
/**
*
*
* @author Franz-Josef Elmer
*/
public class PropertyAssignmentComparatorFactory extends ComparatorFactory
{
private static final Map<String, Comparator<PropertyAssignment>> COMPARATORS_BY_FIELD = new HashMap<>();
static
{
COMPARATORS_BY_FIELD.put(PropertyAssignmentSortOptions.CODE, new AbstractPropertyAssignmentComparator()
{
@Override
protected String getValue(PropertyType propertyType)
{
return propertyType.getCode();
}
});
COMPARATORS_BY_FIELD.put(PropertyAssignmentSortOptions.LABEL, new AbstractPropertyAssignmentComparator()
{
@Override
protected String getValue(PropertyType propertyType)
{
return propertyType.getLabel();
}
});
}
@Override
public boolean accepts(Class<?> sortOptionsClass)
{
return PropertyAssignmentSortOptions.class.isAssignableFrom(sortOptionsClass);
}
@Override
public Comparator<PropertyAssignment> getComparator(String field)
{
return COMPARATORS_BY_FIELD.get(field);
}
@Override
public Comparator<PropertyAssignment> getDefaultComparator()
{
return COMPARATORS_BY_FIELD.get(PropertyAssignmentSortOptions.CODE);
}
private abstract static class AbstractPropertyAssignmentComparator extends AbstractStringComparator<PropertyAssignment>
{
@Override
protected String getValue(PropertyAssignment assignment)
{
PropertyType propertyType = assignment.getPropertyType();
String v = propertyType == null ? null : getValue(propertyType);
return v == null ? "" : v;
}
protected abstract String getValue(PropertyType propertyType);
}
}
......@@ -21,6 +21,7 @@ import java.util.LinkedList;
import java.util.List;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.globalsearch.GlobalSearchObjectComparatorFactory;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.property.PropertyAssignmentComparatorFactory;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.tag.TagComparatorFactory;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.vocabulary.VocabularyTermComparatorFactory;
......@@ -40,6 +41,7 @@ public abstract class ComparatorFactory
factories.add(new VocabularyTermComparatorFactory());
factories.add(new EntityWithPropertiesComparatorFactory());
factories.add(new EntityComparatorFactory());
factories.add(new PropertyAssignmentComparatorFactory());
}
public abstract boolean accepts(Class<?> sortOptionsClass);
......
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.dataset;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyAssignmentTranslator;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.lemnik.eodsql.QueryTool;
/**
*
*
* @author Franz-Josef Elmer
*/
@Component
public class DataSetPropertyAssignmentTranslator extends PropertyAssignmentTranslator implements IDataSetPropertyAssignmentTranslator
{
@Override
protected List<ObjectRelationRecord> loadRecords(LongOpenHashSet dataSetTypeIds)
{
DataSetQuery query = QueryTool.getManagedQuery(DataSetQuery.class);
return query.getPropertyAssignmentIds(dataSetTypeIds);
}
@Override
protected Map<Long, PropertyAssignment> translateRelated(TranslationContext context,
Collection<Long> dataSetTypePropertyTypeIds, PropertyAssignmentFetchOptions relatedFetchOptions)
{
DataSetQuery query = QueryTool.getManagedQuery(DataSetQuery.class);
return getAssignments(query.getPropertyAssignments(new LongOpenHashSet(dataSetTypePropertyTypeIds)));
}
}
......@@ -22,6 +22,7 @@ import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.Obje
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.history.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.MaterialPropertyRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyAssignmentRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyRecord;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
......@@ -183,5 +184,13 @@ public interface DataSetQuery extends ObjectQuery
@Select(sql = "select d.id as objectId, d.pers_id_modifier as relatedId from data d where d.id = any(?{1})", parameterBindings = {
LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getModifierIds(LongSet dataSetIds);
@Select(sql = "select dsty_id as objectId, id as relatedId from data_set_type_property_types where dsty_id = any(?{1})",
parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getPropertyAssignmentIds(LongSet dataSetTypeIds);
@Select(sql = "select * from data_set_type_property_types where id = any(?{1})", parameterBindings = {
LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<PropertyAssignmentRecord> getPropertyAssignments(LongSet dataSetTypePropertyTypeIds);
}
......@@ -16,7 +16,9 @@
package ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.dataset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -25,6 +27,8 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSetKind;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSetType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetTypeFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.SortAndPage;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.AbstractCachingTranslator;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationResults;
......@@ -39,12 +43,15 @@ public class DataSetTypeTranslator extends AbstractCachingTranslator<Long, DataS
@Autowired
private IDataSetTypeBaseTranslator baseTranslator;
@Autowired
private IDataSetPropertyAssignmentTranslator assignmentTranslator;
@Override
protected DataSetType createObject(TranslationContext context, Long typeId, DataSetTypeFetchOptions fetchOptions)
{
final DataSetType type = new DataSetType();
type.setFetchOptions(new DataSetTypeFetchOptions());
type.setFetchOptions(fetchOptions);
return type;
}
......@@ -54,6 +61,11 @@ public class DataSetTypeTranslator extends AbstractCachingTranslator<Long, DataS
TranslationResults relations = new TranslationResults();
relations.put(IDataSetTypeBaseTranslator.class, baseTranslator.translate(context, typeIds, null));
if (fetchOptions.hasPropertyAssignments())
{
relations.put(IDataSetPropertyAssignmentTranslator.class,
assignmentTranslator.translate(context, typeIds, fetchOptions.withPropertyAssignments()));
}
return relations;
}
......@@ -70,6 +82,13 @@ public class DataSetTypeTranslator extends AbstractCachingTranslator<Long, DataS
result.setKind(DataSetKind.valueOf(baseRecord.kind));
result.setDescription(baseRecord.description);
result.setModificationDate(baseRecord.modificationDate);
if (fetchOptions.hasPropertyAssignments())
{
Collection<PropertyAssignment> assignments = relations.get(IDataSetPropertyAssignmentTranslator.class, typeId);
List<PropertyAssignment> propertyAssignments = new ArrayList<>(assignments);
result.setPropertyAssignments(new SortAndPage().sortAndPage(propertyAssignments, fetchOptions.withPropertyAssignments()));
}
}
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.dataset;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.IPropertyAssignmentTranslator;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface IDataSetPropertyAssignmentTranslator extends IPropertyAssignmentTranslator
{
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.experiment;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyAssignmentTranslator;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.lemnik.eodsql.QueryTool;
/**
*
*
* @author Franz-Josef Elmer
*/
@Component
public class ExperimentPropertyAssignmentTranslator extends PropertyAssignmentTranslator implements IExperimentPropertyAssignmentTranslator
{
@Override
protected List<ObjectRelationRecord> loadRecords(LongOpenHashSet experimentTypeIds)
{
ExperimentQuery query = QueryTool.getManagedQuery(ExperimentQuery.class);
return query.getPropertyAssignmentIds(experimentTypeIds);
}
@Override
protected Map<Long, PropertyAssignment> translateRelated(TranslationContext context,
Collection<Long> experimentTypePropertyTypeIds, PropertyAssignmentFetchOptions relatedFetchOptions)
{
ExperimentQuery query = QueryTool.getManagedQuery(ExperimentQuery.class);
return getAssignments(query.getPropertyAssignments(new LongOpenHashSet(experimentTypePropertyTypeIds)));
}
}
......@@ -26,6 +26,7 @@ import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.Obje
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.history.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.MaterialPropertyRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyAssignmentRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyRecord;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
......@@ -105,4 +106,11 @@ public interface ExperimentQuery extends ObjectQuery
@Select(sql = "select ma.expe_id as objectId, ma.mepr_id as relatedId from metaproject_assignments ma where ma.expe_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getTagIds(LongSet experimentIds);
@Select(sql = "select exty_id as objectId, id as relatedId from experiment_type_property_types where exty_id = any(?{1})",
parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getPropertyAssignmentIds(LongSet experimentTypeIds);
@Select(sql = "select * from experiment_type_property_types where id = any(?{1})", parameterBindings = {
LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<PropertyAssignmentRecord> getPropertyAssignments(LongSet experimentTypePropertyTypeIds);
}
......@@ -16,7 +16,9 @@
package ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.experiment;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -24,6 +26,8 @@ import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.ExperimentType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentTypeFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.SortAndPage;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.AbstractCachingTranslator;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationResults;
......@@ -38,12 +42,15 @@ public class ExperimentTypeTranslator extends AbstractCachingTranslator<Long, Ex
@Autowired
private IExperimentTypeBaseTranslator baseTranslator;
@Autowired
private IExperimentPropertyAssignmentTranslator assignmentTranslator;
@Override
protected ExperimentType createObject(TranslationContext context, Long typeId, ExperimentTypeFetchOptions fetchOptions)
{
final ExperimentType type = new ExperimentType();
type.setFetchOptions(new ExperimentTypeFetchOptions());
type.setFetchOptions(fetchOptions);
return type;
}
......@@ -53,6 +60,11 @@ public class ExperimentTypeTranslator extends AbstractCachingTranslator<Long, Ex
TranslationResults relations = new TranslationResults();
relations.put(IExperimentTypeBaseTranslator.class, baseTranslator.translate(context, typeIds, null));
if (fetchOptions.hasPropertyAssignments())
{
relations.put(IExperimentPropertyAssignmentTranslator.class,
assignmentTranslator.translate(context, typeIds, fetchOptions.withPropertyAssignments()));
}
return relations;
}
......@@ -68,6 +80,13 @@ public class ExperimentTypeTranslator extends AbstractCachingTranslator<Long, Ex
result.setCode(baseRecord.code);
result.setDescription(baseRecord.description);
result.setModificationDate(baseRecord.modificationDate);
if (fetchOptions.hasPropertyAssignments())
{
Collection<PropertyAssignment> assignments = relations.get(IExperimentPropertyAssignmentTranslator.class, typeId);
List<PropertyAssignment> propertyAssignments = new ArrayList<>(assignments);
result.setPropertyAssignments(new SortAndPage().sortAndPage(propertyAssignments, fetchOptions.withPropertyAssignments()));
}
}
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.experiment;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.IPropertyAssignmentTranslator;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface IExperimentPropertyAssignmentTranslator extends IPropertyAssignmentTranslator
{
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.material;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.IPropertyAssignmentTranslator;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface IMaterialPropertyAssignmentTranslator extends IPropertyAssignmentTranslator
{
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.material;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyAssignmentTranslator;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.lemnik.eodsql.QueryTool;
/**
*
*
* @author Franz-Josef Elmer
*/
@Component
public class MaterialPropertyAssignmentTranslator extends PropertyAssignmentTranslator implements IMaterialPropertyAssignmentTranslator
{
@Override
protected List<ObjectRelationRecord> loadRecords(LongOpenHashSet materialTypeIds)
{
MaterialQuery query = QueryTool.getManagedQuery(MaterialQuery.class);
return query.getPropertyAssignmentIds(materialTypeIds);
}
@Override
protected Map<Long, PropertyAssignment> translateRelated(TranslationContext context,
Collection<Long> materialTypePropertyTaypeIds, PropertyAssignmentFetchOptions relatedFetchOptions)
{
MaterialQuery query = QueryTool.getManagedQuery(MaterialQuery.class);
return getAssignments(query.getPropertyAssignments(new LongOpenHashSet(materialTypePropertyTaypeIds)));
}
}
......@@ -16,20 +16,20 @@
package ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.material;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import java.util.List;
import net.lemnik.eodsql.Select;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectQuery;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.history.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.MaterialPropertyRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyAssignmentRecord;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.property.PropertyRecord;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.lemnik.eodsql.Select;
/**
* @author pkupczyk
*/
......@@ -79,5 +79,13 @@ public interface MaterialQuery extends ObjectQuery
@Select(sql = "select ma.mate_id as objectId, ma.mepr_id as relatedId from metaproject_assignments ma where ma.mate_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getTagIds(LongSet materialIds);
@Select(sql = "select maty_id as objectId, id as relatedId from material_type_property_types where maty_id = any(?{1})",
parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getPropertyAssignmentIds(LongSet materialTypeIds);
@Select(sql = "select * from material_type_property_types where id = any(?{1})", parameterBindings = {
LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<PropertyAssignmentRecord> getPropertyAssignments(LongSet materialTypePropertyTypeIds);
}
......@@ -16,7 +16,9 @@
package ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.material;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -24,6 +26,8 @@ import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.SortAndPage;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.AbstractCachingTranslator;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationResults;
......@@ -38,12 +42,15 @@ public class MaterialTypeTranslator extends AbstractCachingTranslator<Long, Mate
@Autowired
private IMaterialTypeBaseTranslator baseTranslator;
@Autowired
private IMaterialPropertyAssignmentTranslator assignmentTranslator;
@Override
protected MaterialType createObject(TranslationContext context, Long typeId, MaterialTypeFetchOptions fetchOptions)
{
final MaterialType materialType = new MaterialType();
materialType.setFetchOptions(new MaterialTypeFetchOptions());
materialType.setFetchOptions(fetchOptions);
return materialType;
}
......@@ -53,6 +60,11 @@ public class MaterialTypeTranslator extends AbstractCachingTranslator<Long, Mate
TranslationResults relations = new TranslationResults();
relations.put(IMaterialTypeBaseTranslator.class, baseTranslator.translate(context, typeIds, null));
if (fetchOptions.hasPropertyAssignments())
{
relations.put(IMaterialPropertyAssignmentTranslator.class,
assignmentTranslator.translate(context, typeIds, fetchOptions.withPropertyAssignments()));
}
return relations;
}
......@@ -68,6 +80,13 @@ public class MaterialTypeTranslator extends AbstractCachingTranslator<Long, Mate
result.setCode(baseRecord.code);
result.setDescription(baseRecord.description);
result.setModificationDate(baseRecord.modificationDate);
if (fetchOptions.hasPropertyAssignments())
{
Collection<PropertyAssignment> assignments = relations.get(IMaterialPropertyAssignmentTranslator.class, typeId);
List<PropertyAssignment> propertyAssignments = new ArrayList<>(assignments);
result.setPropertyAssignments(new SortAndPage().sortAndPage(propertyAssignments, fetchOptions.withPropertyAssignments()));
}
}
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.property;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.IObjectToManyRelationTranslator;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface IPropertyAssignmentTranslator extends IObjectToManyRelationTranslator<PropertyAssignment, PropertyAssignmentFetchOptions>
{
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.property;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectBaseRecord;
/**
*
*
* @author Franz-Josef Elmer
*/
public class PropertyAssignmentRecord extends ObjectBaseRecord
{
public Boolean is_mandatory;
public Long prty_id;
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.property;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.DataTypeCode;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectToManyRelationTranslator;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.lemnik.eodsql.QueryTool;
/**
*
*
* @author Franz-Josef Elmer
*/
public abstract class PropertyAssignmentTranslator extends ObjectToManyRelationTranslator<PropertyAssignment, PropertyAssignmentFetchOptions>
{
protected Map<Long, PropertyAssignment> getAssignments(Collection<PropertyAssignmentRecord> assignmentRecords)
{
Map<Long, PropertyAssignment> assignments = new HashMap<>();
Map<Long, PropertyAssignment> assignmentsByPropertyTypeId = new HashMap<>();
for (PropertyAssignmentRecord assignmentRecord : assignmentRecords)
{
PropertyAssignment assignment = new PropertyAssignment();
assignment.setMandatory(assignmentRecord.is_mandatory);
assignments.put(assignmentRecord.id, assignment);
assignmentsByPropertyTypeId.put(assignmentRecord.prty_id, assignment);
}
PropertyTypeQuery query = QueryTool.getManagedQuery(PropertyTypeQuery.class);
List<PropertyTypeRecord> propertyTypeRecords = query.getPropertyTypes(new LongOpenHashSet(assignmentsByPropertyTypeId.keySet()));
for (PropertyTypeRecord propertyTypeRecord : propertyTypeRecords)
{
Long propertyTypeId = propertyTypeRecord.id;
PropertyType propertyType = new PropertyType();
propertyType.setCode(propertyTypeRecord.code);
propertyType.setLabel(propertyTypeRecord.label);
propertyType.setDescription(propertyTypeRecord.description);
propertyType.setDataTypeCode(DataTypeCode.valueOf(propertyTypeRecord.dataSetTypeCode));
propertyType.setInternalNameSpace(propertyTypeRecord.is_internal_namespace);
PropertyAssignment assignment = assignmentsByPropertyTypeId.get(propertyTypeId);
assignment.setPropertyType(propertyType);
}
return assignments;
}
@Override
protected Collection<PropertyAssignment> createCollection()
{
return new ArrayList<>();
}
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.property;
import java.util.List;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectQuery;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.lemnik.eodsql.Select;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface PropertyTypeQuery extends ObjectQuery
{
@Select(sql = "select pt.*, t.code as dataSetTypeCode "
+ "from property_types pt join data_types t on pt.daty_id=t.id where pt.id = any(?{1})",
parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<PropertyTypeRecord> getPropertyTypes(LongSet propertyTypeIds);
}
/*
* Copyright 2016 ETH Zuerich, SIS
*
* 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.asapi.v3.translator.entity.property;
import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.common.ObjectBaseRecord;
/**
*
*
* @author Franz-Josef Elmer
*/
public class PropertyTypeRecord extends ObjectBaseRecord
{
public String code;
public String label;
public String description;
public Boolean is_internal_namespace;
public String dataSetTypeCode;
}
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