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

SSDM-944 : V3 AS API - improve performance of map and search methods - HistoryRelation

SVN: 34434
parent b471e532
No related branches found
No related tags found
No related merge requests found
Showing
with 982 additions and 13 deletions
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package ch.ethz.sis.openbis.generic.server.api.v3.executor.method; package ch.ethz.sis.openbis.generic.server.api.v3.executor.method;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.ISearchObjectExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.ISearchObjectExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ISearchMaterialExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ISearchMaterialExecutor;
...@@ -31,7 +30,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; ...@@ -31,7 +30,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE;
/** /**
* @author pkupczyk * @author pkupczyk
*/ */
@Component // @Component
public class SearchMaterialMethodExecutor extends public class SearchMaterialMethodExecutor extends
AbstractSearchMethodExecutor<Material, MaterialPE, MaterialSearchCriterion, MaterialFetchOptions> AbstractSearchMethodExecutor<Material, MaterialPE, MaterialSearchCriterion, MaterialFetchOptions>
implements ISearchMaterialMethodExecutor implements ISearchMaterialMethodExecutor
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package ch.ethz.sis.openbis.generic.server.api.v3.executor.method; package ch.ethz.sis.openbis.generic.server.api.v3.executor.method;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.ISearchObjectExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.ISearchObjectExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ISearchMaterialIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ISearchMaterialIdExecutor;
...@@ -29,7 +30,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.MaterialSearchCriter ...@@ -29,7 +30,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.MaterialSearchCriter
/** /**
* @author pkupczyk * @author pkupczyk
*/ */
// @Component @Component
public class SearchMaterialSqlMethodExecutor extends public class SearchMaterialSqlMethodExecutor extends
AbstractSearchMethodExecutor<Material, Long, MaterialSearchCriterion, MaterialFetchOptions> AbstractSearchMethodExecutor<Material, Long, MaterialSearchCriterion, MaterialFetchOptions>
implements ISearchMaterialMethodExecutor implements ISearchMaterialMethodExecutor
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset; package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -26,8 +28,8 @@ import org.springframework.stereotype.Component; ...@@ -26,8 +28,8 @@ import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.AbstractCachingTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.AbstractCachingTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.Relations; import ch.ethz.sis.openbis.generic.server.api.v3.translator.Relations;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext; import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset.sql.DataSetHistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.IExperimentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.IExperimentTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.IHistoryTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.material.IMaterialPropertyTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.material.IMaterialPropertyTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.IPersonTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.IPersonTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.property.IPropertyTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.property.IPropertyTranslator;
...@@ -73,9 +75,6 @@ public class DataSetTranslator extends AbstractCachingTranslator<DataPE, DataSet ...@@ -73,9 +75,6 @@ public class DataSetTranslator extends AbstractCachingTranslator<DataPE, DataSet
@Autowired @Autowired
private IExternalDataTranslator externalDataTranslator; private IExternalDataTranslator externalDataTranslator;
@Autowired
private IHistoryTranslator historyTranslator;
@Override @Override
protected boolean shouldTranslate(TranslationContext context, DataPE input, DataSetFetchOptions fetchOptions) protected boolean shouldTranslate(TranslationContext context, DataPE input, DataSetFetchOptions fetchOptions)
{ {
...@@ -97,6 +96,24 @@ public class DataSetTranslator extends AbstractCachingTranslator<DataPE, DataSet ...@@ -97,6 +96,24 @@ public class DataSetTranslator extends AbstractCachingTranslator<DataPE, DataSet
return dataSet; return dataSet;
} }
@Override
protected Relations getObjectsRelations(TranslationContext context, Collection<DataPE> dataSets, DataSetFetchOptions fetchOptions)
{
Relations relations = new Relations();
if (fetchOptions.hasHistory())
{
Set<Long> dataSetIds = new HashSet<Long>();
for (DataPE dataSet : dataSets)
{
dataSetIds.add(dataSet.getId());
}
relations.add(createRelation(DataSetHistoryRelation.class, context, dataSetIds, fetchOptions.withHistory()));
}
return relations;
}
@Override @Override
protected void updateObject(TranslationContext context, DataPE dataPe, DataSet result, Relations relations, DataSetFetchOptions fetchOptions) protected void updateObject(TranslationContext context, DataPE dataPe, DataSet result, Relations relations, DataSetFetchOptions fetchOptions)
{ {
...@@ -194,7 +211,8 @@ public class DataSetTranslator extends AbstractCachingTranslator<DataPE, DataSet ...@@ -194,7 +211,8 @@ public class DataSetTranslator extends AbstractCachingTranslator<DataPE, DataSet
if (fetchOptions.hasHistory()) if (fetchOptions.hasHistory())
{ {
result.setHistory(historyTranslator.translate(context, dataPe, fetchOptions.withHistory())); DataSetHistoryRelation relation = relations.get(DataSetHistoryRelation.class);
result.setHistory(relation.getRelated(dataPe.getId()));
result.getFetchOptions().withHistoryUsing(fetchOptions.withHistory()); result.getFetchOptions().withHistoryUsing(fetchOptions.withHistory());
} }
} }
......
/*
* 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.translator.entity.dataset.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.lemnik.eodsql.QueryTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.DataSetRelationType;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.RelationHistoryEntry;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.person.Person;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.history.HistoryEntryFetchOptions;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.DataSetPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.RelationType;
/**
* @author pkupczyk
*/
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DataSetHistoryRelation extends HistoryRelation
{
@Autowired
private IDAOFactory daoFactory;
public DataSetHistoryRelation(TranslationContext context, Collection<Long> entityIds, HistoryEntryFetchOptions fetchOptions)
{
super(context, entityIds, fetchOptions);
}
@Override
protected List<HistoryPropertyRecord> loadPropertyHistory(Collection<Long> entityIds)
{
DataSetQuery query = QueryTool.getManagedQuery(DataSetQuery.class);
return query.getPropertiesHistory(new LongOpenHashSet(entityIds));
}
@Override
protected List<? extends HistoryRelationshipRecord> loadRelationshipHistory(Collection<Long> entityIds)
{
DataSetQuery query = QueryTool.getManagedQuery(DataSetQuery.class);
return query.getRelationshipsHistory(new LongOpenHashSet(entityIds));
}
@Override
protected RelationHistoryEntry createRelationshipEntry(HistoryRelationshipRecord record, Map<Long, Person> authorMap)
{
RelationHistoryEntry entry = super.createRelationshipEntry(record, authorMap);
DataSetRelationshipRecord dataSetRecord = (DataSetRelationshipRecord) record;
if (dataSetRecord.experimentId != null)
{
entry.setRelationType(DataSetRelationType.EXPERIMENT);
entry.setRelatedObjectId(new ExperimentPermId(dataSetRecord.relatedObjectId));
} else if (dataSetRecord.sampleId != null)
{
entry.setRelationType(DataSetRelationType.SAMPLE);
entry.setRelatedObjectId(new SamplePermId(dataSetRecord.relatedObjectId));
} else if (dataSetRecord.dataSetId != null)
{
RelationType relationType = RelationType.valueOf(dataSetRecord.relationType);
switch (relationType)
{
case PARENT:
entry.setRelationType(DataSetRelationType.CHILD);
break;
case CHILD:
entry.setRelationType(DataSetRelationType.PARENT);
break;
case CONTAINER:
entry.setRelationType(DataSetRelationType.CONTAINED);
break;
case CONTAINED:
case COMPONENT:
entry.setRelationType(DataSetRelationType.CONTAINER);
break;
default:
throw new IllegalArgumentException("Unsupported relation type: " + relationType);
}
entry.setRelatedObjectId(new DataSetPermId(dataSetRecord.relatedObjectId));
}
return entry;
}
}
/*
* 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.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset.sql;
import it.unimi.dsi.fastutil.longs.LongSet;
import java.util.List;
import net.lemnik.eodsql.Select;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectQuery;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
/**
* @author pkupczyk
*/
public interface DataSetQuery extends ObjectQuery
{
@Select(sql = "select dph.ds_id as entityId, dph.pers_id_author as authorId, pt.code as propertyCode, dph.value as propertyValue, dph.material as materialPropertyValue, dph.vocabulary_term as vocabularyPropertyValue, dph.valid_from_timestamp as validFrom, dph.valid_until_timestamp as validTo "
+ "from data_set_properties_history dph "
+ "left join data_set_type_property_types dtpt on dph.dstpt_id = dtpt.id "
+ "left join property_types pt on dtpt.prty_id = pt.id "
+ "where dph.ds_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<HistoryPropertyRecord> getPropertiesHistory(LongSet dataSetIds);
@Select(sql = "select drh.main_data_id as entityId, drh.pers_id_author as authorId, drh.relation_type as relationType, "
+ "drh.entity_perm_id as relatedObjectId, drh.valid_from_timestamp as validFrom, drh.valid_until_timestamp as validTo, "
+ "drh.expe_id as experimentId, drh.samp_id as sampleId, drh.data_id as dataSetId "
+ "from data_set_relationships_history drh where drh.valid_until_timestamp is not null and drh.main_data_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<DataSetRelationshipRecord> getRelationshipsHistory(LongSet dataSetIds);
}
/*
* 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.translator.entity.dataset.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
/**
* @author pkupczyk
*/
public class DataSetRelationshipRecord extends HistoryRelationshipRecord
{
public Long experimentId;
public Long sampleId;
public Long dataSetId;
}
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment; package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -29,7 +31,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.translator.Relations; ...@@ -29,7 +31,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.translator.Relations;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext; import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.attachment.IAttachmentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.attachment.IAttachmentTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset.IDataSetTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset.IDataSetTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.IHistoryTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.sql.ExperimentHistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.material.IMaterialPropertyTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.material.IMaterialPropertyTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.IPersonTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.IPersonTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project.IProjectTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project.IProjectTranslator;
...@@ -85,9 +87,6 @@ public class ExperimentTranslator extends AbstractCachingTranslator<ExperimentPE ...@@ -85,9 +87,6 @@ public class ExperimentTranslator extends AbstractCachingTranslator<ExperimentPE
@Autowired @Autowired
private ITagTranslator tagTranslator; private ITagTranslator tagTranslator;
@Autowired
private IHistoryTranslator historyTranslator;
@Override @Override
protected boolean shouldTranslate(TranslationContext context, ExperimentPE input, ExperimentFetchOptions fetchOptions) protected boolean shouldTranslate(TranslationContext context, ExperimentPE input, ExperimentFetchOptions fetchOptions)
{ {
...@@ -109,6 +108,24 @@ public class ExperimentTranslator extends AbstractCachingTranslator<ExperimentPE ...@@ -109,6 +108,24 @@ public class ExperimentTranslator extends AbstractCachingTranslator<ExperimentPE
return result; return result;
} }
@Override
protected Relations getObjectsRelations(TranslationContext context, Collection<ExperimentPE> experiments, ExperimentFetchOptions fetchOptions)
{
Relations relations = new Relations();
if (fetchOptions.hasHistory())
{
Set<Long> experimentIds = new HashSet<Long>();
for (ExperimentPE experiment : experiments)
{
experimentIds.add(experiment.getId());
}
relations.add(createRelation(ExperimentHistoryRelation.class, context, experimentIds, fetchOptions.withHistory()));
}
return relations;
}
@Override @Override
protected void updateObject(TranslationContext context, ExperimentPE experiment, Experiment result, Relations relations, protected void updateObject(TranslationContext context, ExperimentPE experiment, Experiment result, Relations relations,
ExperimentFetchOptions fetchOptions) ExperimentFetchOptions fetchOptions)
...@@ -179,7 +196,8 @@ public class ExperimentTranslator extends AbstractCachingTranslator<ExperimentPE ...@@ -179,7 +196,8 @@ public class ExperimentTranslator extends AbstractCachingTranslator<ExperimentPE
if (fetchOptions.hasHistory()) if (fetchOptions.hasHistory())
{ {
result.setHistory(historyTranslator.translate(context, experiment, fetchOptions.withHistory())); ExperimentHistoryRelation relation = relations.get(ExperimentHistoryRelation.class);
result.setHistory(relation.getRelated(experiment.getId()));
result.getFetchOptions().withHistoryUsing(fetchOptions.withHistory()); result.getFetchOptions().withHistoryUsing(fetchOptions.withHistory());
} }
} }
......
/*
* 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.translator.entity.experiment.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.lemnik.eodsql.QueryTool;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.ExperimentRelationType;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.RelationHistoryEntry;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.person.Person;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.history.HistoryEntryFetchOptions;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.DataSetPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId;
/**
* @author pkupczyk
*/
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExperimentHistoryRelation extends HistoryRelation
{
public ExperimentHistoryRelation(TranslationContext context, Collection<Long> entityIds, HistoryEntryFetchOptions fetchOptions)
{
super(context, entityIds, fetchOptions);
}
@Override
protected List<HistoryPropertyRecord> loadPropertyHistory(Collection<Long> entityIds)
{
ExperimentQuery query = QueryTool.getManagedQuery(ExperimentQuery.class);
return query.getPropertiesHistory(new LongOpenHashSet(entityIds));
}
@Override
protected List<? extends HistoryRelationshipRecord> loadRelationshipHistory(Collection<Long> entityIds)
{
ExperimentQuery query = QueryTool.getManagedQuery(ExperimentQuery.class);
return query.getRelationshipsHistory(new LongOpenHashSet(entityIds));
}
@Override
protected RelationHistoryEntry createRelationshipEntry(HistoryRelationshipRecord record, Map<Long, Person> authorMap)
{
RelationHistoryEntry entry = super.createRelationshipEntry(record, authorMap);
ExperimentRelationshipRecord experimentRecord = (ExperimentRelationshipRecord) record;
if (experimentRecord.projectId != null)
{
entry.setRelationType(ExperimentRelationType.PROJECT);
entry.setRelatedObjectId(new ProjectPermId(experimentRecord.relatedObjectId));
} else if (experimentRecord.sampleId != null)
{
entry.setRelationType(ExperimentRelationType.SAMPLE);
entry.setRelatedObjectId(new SamplePermId(experimentRecord.relatedObjectId));
} else if (experimentRecord.dataSetId != null)
{
entry.setRelationType(ExperimentRelationType.DATA_SET);
entry.setRelatedObjectId(new DataSetPermId(experimentRecord.relatedObjectId));
}
return entry;
}
}
/*
* 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.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.sql;
import it.unimi.dsi.fastutil.longs.LongSet;
import java.util.List;
import net.lemnik.eodsql.Select;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectQuery;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
/**
* @author pkupczyk
*/
public interface ExperimentQuery extends ObjectQuery
{
@Select(sql = "select eph.expe_id as entityId, eph.pers_id_author as authorId, pt.code as propertyCode, eph.value as propertyValue, eph.material as materialPropertyValue, eph.vocabulary_term as vocabularyPropertyValue, eph.valid_from_timestamp as validFrom, eph.valid_until_timestamp as validTo "
+ "from experiment_properties_history eph "
+ "left join experiment_type_property_types etpt on eph.etpt_id = etpt.id "
+ "left join property_types pt on etpt.prty_id = pt.id "
+ "where eph.expe_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<HistoryPropertyRecord> getPropertiesHistory(LongSet experimentIds);
@Select(sql = "select erh.main_expe_id as entityId, erh.pers_id_author as authorId, erh.relation_type as relationType, "
+ "erh.entity_perm_id as relatedObjectId, erh.valid_from_timestamp as validFrom, erh.valid_until_timestamp as validTo, "
+ "erh.proj_id as projectId, erh.samp_id as sampleId, erh.data_id as dataSetId "
+ "from experiment_relationships_history erh where erh.valid_until_timestamp is not null and erh.main_expe_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ExperimentRelationshipRecord> getRelationshipsHistory(LongSet experimentIds);
}
/*
* 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.translator.entity.experiment.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
/**
* @author pkupczyk
*/
public class ExperimentRelationshipRecord extends HistoryRelationshipRecord
{
public Long projectId;
public Long sampleId;
public Long dataSetId;
}
/*
* 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.translator.entity.history.sql;
import java.util.Date;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectBaseRecord;
/**
* @author pkupczyk
*/
public class HistoryPropertyRecord extends ObjectBaseRecord
{
public Long entityId;
public Long authorId;
public String propertyCode;
public String propertyValue;
public String materialPropertyValue;
public String vocabularyPropertyValue;
public Date validFrom;
public Date validTo;
}
/*
* 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.translator.entity.history.sql;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.Relation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.sql.IPersonSqlTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.HistoryEntry;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.PropertyHistoryEntry;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.RelationHistoryEntry;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.person.Person;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.history.HistoryEntryFetchOptions;
/**
* @author pkupczyk
*/
public abstract class HistoryRelation implements Relation
{
@Autowired
private IPersonSqlTranslator personTranslator;
private TranslationContext context;
private Collection<Long> entityIds;
private HistoryEntryFetchOptions fetchOptions;
private Map<Long, List<HistoryEntry>> entriesMap = new HashMap<Long, List<HistoryEntry>>();
public HistoryRelation(TranslationContext context, Collection<Long> entityIds, HistoryEntryFetchOptions fetchOptions)
{
this.context = context;
this.entityIds = entityIds;
this.fetchOptions = fetchOptions;
}
@SuppressWarnings("hiding")
protected abstract List<? extends HistoryPropertyRecord> loadPropertyHistory(Collection<Long> entityIds);
@SuppressWarnings("hiding")
protected abstract List<? extends HistoryRelationshipRecord> loadRelationshipHistory(Collection<Long> entityIds);
@Override
public void load()
{
List<? extends HistoryPropertyRecord> properties = loadPropertyHistory(entityIds);
List<? extends HistoryRelationshipRecord> relationships = loadRelationshipHistory(entityIds);
Map<Long, Person> authorMap = new HashMap<>();
if (fetchOptions.hasAuthor())
{
Set<Long> authorIds = new HashSet<Long>();
if (properties != null)
{
for (HistoryPropertyRecord property : properties)
{
if (property.authorId != null)
{
authorIds.add(property.authorId);
}
}
}
if (relationships != null)
{
for (HistoryRelationshipRecord relationship : relationships)
{
if (relationship.authorId != null)
{
authorIds.add(relationship.authorId);
}
}
}
authorMap = personTranslator.translate(context, authorIds, fetchOptions.withAuthor());
}
if (properties != null)
{
createPropertyEntries(properties, authorMap);
}
if (relationships != null)
{
createRelationshipEntries(relationships, authorMap);
}
}
private void createPropertyEntries(List<? extends HistoryPropertyRecord> records, Map<Long, Person> authorMap)
{
for (HistoryPropertyRecord record : records)
{
List<HistoryEntry> entries = entriesMap.get(record.entityId);
if (entries == null)
{
entries = new LinkedList<HistoryEntry>();
entriesMap.put(record.entityId, entries);
}
entries.add(createPropertyEntry(record, authorMap));
}
}
protected PropertyHistoryEntry createPropertyEntry(HistoryPropertyRecord record, Map<Long, Person> authorMap)
{
PropertyHistoryEntry entry = new PropertyHistoryEntry();
entry.setFetchOptions(new HistoryEntryFetchOptions());
entry.setValidFrom(record.validFrom);
entry.setValidTo(record.validTo);
entry.setPropertyName(record.propertyCode);
if (record.propertyValue != null)
{
entry.setPropertyValue(record.propertyValue);
} else if (record.vocabularyPropertyValue != null)
{
entry.setPropertyValue(record.vocabularyPropertyValue);
} else if (record.materialPropertyValue != null)
{
entry.setPropertyValue(record.materialPropertyValue);
} else
{
throw new IllegalArgumentException("Unexpected property history entry with all values null");
}
if (fetchOptions.hasAuthor())
{
entry.setAuthor(authorMap.get(record.authorId));
entry.getFetchOptions().withAuthorUsing(fetchOptions.withAuthor());
}
return entry;
}
private void createRelationshipEntries(List<? extends HistoryRelationshipRecord> records, Map<Long, Person> authorMap)
{
for (HistoryRelationshipRecord record : records)
{
List<HistoryEntry> entries = entriesMap.get(record.entityId);
if (entries == null)
{
entries = new LinkedList<HistoryEntry>();
entriesMap.put(record.entityId, entries);
}
entries.add(createRelationshipEntry(record, authorMap));
}
}
protected RelationHistoryEntry createRelationshipEntry(HistoryRelationshipRecord record, Map<Long, Person> authorMap)
{
RelationHistoryEntry entry = new RelationHistoryEntry();
entry.setFetchOptions(new HistoryEntryFetchOptions());
entry.setValidFrom(record.validFrom);
entry.setValidTo(record.validTo);
if (fetchOptions.hasAuthor())
{
entry.setAuthor(authorMap.get(record.authorId));
entry.getFetchOptions().withAuthorUsing(fetchOptions.withAuthor());
}
return entry;
}
public List<HistoryEntry> getRelated(Long entityId)
{
if (entriesMap.containsKey(entityId))
{
return entriesMap.get(entityId);
} else
{
return Collections.emptyList();
}
}
}
/*
* 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.translator.entity.history.sql;
import java.util.Date;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectBaseRecord;
/**
* @author pkupczyk
*/
public class HistoryRelationshipRecord extends ObjectBaseRecord
{
public Long entityId;
public Long authorId;
public String relationType;
public String relatedObjectId;
public Date validFrom;
public Date validTo;
}
/*
* 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.translator.entity.material.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.Collection;
import java.util.List;
import net.lemnik.eodsql.QueryTool;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.history.HistoryEntryFetchOptions;
/**
* @author pkupczyk
*/
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MaterialHistoryRelation extends HistoryRelation
{
public MaterialHistoryRelation(TranslationContext context, Collection<Long> entityIds, HistoryEntryFetchOptions fetchOptions)
{
super(context, entityIds, fetchOptions);
}
@Override
protected List<HistoryPropertyRecord> loadPropertyHistory(Collection<Long> entityIds)
{
MaterialQuery query = QueryTool.getManagedQuery(MaterialQuery.class);
return query.getPropertiesHistory(new LongOpenHashSet(entityIds));
}
@Override
protected List<HistoryRelationshipRecord> loadRelationshipHistory(Collection<Long> entityIds)
{
return null;
}
}
...@@ -25,6 +25,7 @@ import net.lemnik.eodsql.Select; ...@@ -25,6 +25,7 @@ import net.lemnik.eodsql.Select;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectQuery; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectQuery;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectRelationRecord; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectRelationRecord;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper; import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
/** /**
...@@ -54,6 +55,13 @@ public interface MaterialQuery extends ObjectQuery ...@@ -54,6 +55,13 @@ public interface MaterialQuery extends ObjectQuery
+ "where mp.mate_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE) + "where mp.mate_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<MaterialPropertyRecord> getProperties(LongSet materialIds); public List<MaterialPropertyRecord> getProperties(LongSet materialIds);
@Select(sql = "select mph.mate_id as entityId, mph.pers_id_author as authorId, pt.code as propertyCode, mph.value as propertyValue, mph.material as materialPropertyValue, mph.vocabulary_term as vocabularyPropertyValue, mph.valid_from_timestamp as validFrom, mph.valid_until_timestamp as validTo "
+ "from material_properties_history mph "
+ "left join material_type_property_types mtpt on mph.mtpt_id = mtpt.id "
+ "left join property_types pt on mtpt.prty_id = pt.id "
+ "where mph.mate_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<HistoryPropertyRecord> getPropertiesHistory(LongSet materialIds);
@Select(sql = "select mp.mate_id as materialId, pt.code as propertyCode, mp.mate_prop_id as propertyValue " @Select(sql = "select mp.mate_id as materialId, pt.code as propertyCode, mp.mate_prop_id as propertyValue "
+ "from material_properties mp " + "from material_properties mp "
+ "left join material_type_property_types mtpt on mp.mtpt_id = mtpt.id " + "left join material_type_property_types mtpt on mp.mtpt_id = mtpt.id "
......
...@@ -75,6 +75,11 @@ public class MaterialSqlTranslator extends AbstractCachingTranslator<Long, Mater ...@@ -75,6 +75,11 @@ public class MaterialSqlTranslator extends AbstractCachingTranslator<Long, Mater
relations.add(createRelation(MaterialTagsRelation.class, context, materialIds, fetchOptions.withTags())); relations.add(createRelation(MaterialTagsRelation.class, context, materialIds, fetchOptions.withTags()));
} }
if (fetchOptions.hasHistory())
{
relations.add(createRelation(MaterialHistoryRelation.class, context, materialIds, fetchOptions.withHistory()));
}
return relations; return relations;
} }
...@@ -125,5 +130,12 @@ public class MaterialSqlTranslator extends AbstractCachingTranslator<Long, Mater ...@@ -125,5 +130,12 @@ public class MaterialSqlTranslator extends AbstractCachingTranslator<Long, Mater
result.getFetchOptions().withTagsUsing(fetchOptions.withTags()); result.getFetchOptions().withTagsUsing(fetchOptions.withTags());
} }
if (fetchOptions.hasHistory())
{
MaterialHistoryRelation relation = relations.get(MaterialHistoryRelation.class);
result.setHistory(relation.getRelated(materialId));
result.getFetchOptions().withHistoryUsing(fetchOptions.withHistory());
}
} }
} }
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project; package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -29,6 +32,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext; ...@@ -29,6 +32,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.attachment.IAttachmentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.attachment.IAttachmentTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.IExperimentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.IExperimentTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.IPersonTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.IPersonTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project.sql.ProjectHistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.ISpaceTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.ISpaceTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.Attachment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.Attachment;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment;
...@@ -81,6 +85,24 @@ public class ProjectTranslator extends AbstractCachingTranslator<ProjectPE, Proj ...@@ -81,6 +85,24 @@ public class ProjectTranslator extends AbstractCachingTranslator<ProjectPE, Proj
return result; return result;
} }
@Override
protected Relations getObjectsRelations(TranslationContext context, Collection<ProjectPE> projects, ProjectFetchOptions fetchOptions)
{
Relations relations = new Relations();
if (fetchOptions.hasHistory())
{
Set<Long> projectIds = new HashSet<Long>();
for (ProjectPE project : projects)
{
projectIds.add(project.getId());
}
relations.add(createRelation(ProjectHistoryRelation.class, context, projectIds, fetchOptions.withHistory()));
}
return relations;
}
@Override @Override
protected void updateObject(TranslationContext context, ProjectPE project, Project result, Relations relations, ProjectFetchOptions fetchOptions) protected void updateObject(TranslationContext context, ProjectPE project, Project result, Relations relations, ProjectFetchOptions fetchOptions)
{ {
...@@ -123,5 +145,12 @@ public class ProjectTranslator extends AbstractCachingTranslator<ProjectPE, Proj ...@@ -123,5 +145,12 @@ public class ProjectTranslator extends AbstractCachingTranslator<ProjectPE, Proj
result.getFetchOptions().withAttachmentsUsing(fetchOptions.withAttachments()); result.getFetchOptions().withAttachmentsUsing(fetchOptions.withAttachments());
} }
if (fetchOptions.hasHistory())
{
ProjectHistoryRelation relation = relations.get(ProjectHistoryRelation.class);
result.setHistory(relation.getRelated(project.getId()));
result.getFetchOptions().withHistoryUsing(fetchOptions.withHistory());
}
} }
} }
/*
* 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.translator.entity.project.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.lemnik.eodsql.QueryTool;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryPropertyRecord;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelation;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.ProjectRelationType;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.history.RelationHistoryEntry;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.person.Person;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.history.HistoryEntryFetchOptions;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.SpacePermId;
/**
* @author pkupczyk
*/
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ProjectHistoryRelation extends HistoryRelation
{
public ProjectHistoryRelation(TranslationContext context, Collection<Long> entityIds, HistoryEntryFetchOptions fetchOptions)
{
super(context, entityIds, fetchOptions);
}
@Override
protected List<HistoryPropertyRecord> loadPropertyHistory(Collection<Long> entityIds)
{
return null;
}
@Override
protected List<? extends HistoryRelationshipRecord> loadRelationshipHistory(Collection<Long> entityIds)
{
ProjectQuery query = QueryTool.getManagedQuery(ProjectQuery.class);
return query.getRelationshipsHistory(new LongOpenHashSet(entityIds));
}
@Override
protected RelationHistoryEntry createRelationshipEntry(HistoryRelationshipRecord record, Map<Long, Person> authorMap)
{
RelationHistoryEntry entry = super.createRelationshipEntry(record, authorMap);
ProjectRelationshipRecord projectRecord = (ProjectRelationshipRecord) record;
if (projectRecord.spaceId != null)
{
entry.setRelationType(ProjectRelationType.SPACE);
entry.setRelatedObjectId(new SpacePermId(projectRecord.relatedObjectId));
} else if (projectRecord.experimentId != null)
{
entry.setRelationType(ProjectRelationType.EXPERIMENT);
entry.setRelatedObjectId(new ExperimentPermId(projectRecord.relatedObjectId));
}
return entry;
}
}
/*
* 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.ethz.sis.openbis.generic.server.api.v3.translator.entity.project.sql;
import it.unimi.dsi.fastutil.longs.LongSet;
import java.util.List;
import net.lemnik.eodsql.Select;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectQuery;
import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
/**
* @author pkupczyk
*/
public interface ProjectQuery extends ObjectQuery
{
@Select(sql = "select prh.main_proj_id as entityId, prh.pers_id_author as authorId, prh.relation_type as relationType, "
+ "prh.entity_perm_id as relatedObjectId, prh.valid_from_timestamp as validFrom, prh.valid_until_timestamp as validTo, "
+ "prh.space_id as spaceId, prh.expe_id as experimentId "
+ "from project_relationships_history prh where prh.valid_until_timestamp is not null and prh.main_proj_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ProjectRelationshipRecord> getRelationshipsHistory(LongSet projectIds);
}
/*
* 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.translator.entity.project.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.history.sql.HistoryRelationshipRecord;
/**
* @author pkupczyk
*/
public class ProjectRelationshipRecord extends HistoryRelationshipRecord
{
public Long spaceId;
public Long experimentId;
}
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