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

SSDM-2318 : V3 AS API - improve performance of searchSamples - SpaceSqlTranslator

SVN: 34624
parent bc379b09
No related branches found
No related tags found
No related merge requests found
Showing
with 767 additions and 22 deletions
......@@ -17,7 +17,6 @@
package ch.ethz.sis.openbis.generic.server.api.v3.executor.method;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.IMapObjectByIdExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.space.IMapSpaceByIdExecutor;
......@@ -31,7 +30,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
@Component
// @Component
public class MapSpaceMethodExecutor extends AbstractMapMethodExecutor<ISpaceId, SpacePE, Space, SpaceFetchOptions> implements IMapSpaceMethodExecutor
{
......
/*
* 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.executor.method;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.IMapObjectByIdExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.space.IMapSpaceByIdExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.ITranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.sql.ISpaceSqlTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.space.Space;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.ISpaceId;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
@Component
public class MapSpaceSqlMethodExecutor extends AbstractMapMethodExecutor<ISpaceId, Long, Space, SpaceFetchOptions> implements IMapSpaceMethodExecutor
{
@Autowired
private IMapSpaceByIdExecutor mapExecutor;
@Autowired
private ISpaceSqlTranslator translator;
@Override
protected IMapObjectByIdExecutor<ISpaceId, Long> getMapExecutor()
{
// TODO replace with ISpaceId -> Long mapExecutor once there is one
return new IMapObjectByIdExecutor<ISpaceId, Long>()
{
@Override
public Map<ISpaceId, Long> map(IOperationContext context, Collection<? extends ISpaceId> ids)
{
Map<ISpaceId, SpacePE> peMap = mapExecutor.map(context, ids);
Map<ISpaceId, Long> idMap = new LinkedHashMap<ISpaceId, Long>();
for (Map.Entry<ISpaceId, SpacePE> peEntry : peMap.entrySet())
{
idMap.put(peEntry.getKey(), peEntry.getValue().getId());
}
return idMap;
}
};
}
@Override
protected ITranslator<Long, Space, SpaceFetchOptions> getTranslator()
{
return translator;
}
}
......@@ -17,7 +17,6 @@
package ch.ethz.sis.openbis.generic.server.api.v3.executor.method;
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.space.ISearchSpaceExecutor;
......@@ -31,7 +30,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
@Component
// @Component
public class SearchSpaceMethodExecutor extends AbstractSearchMethodExecutor<Space, SpacePE, SpaceSearchCriterion, SpaceFetchOptions> implements
ISearchSpaceMethodExecutor
{
......
/*
* 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.executor.method;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
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.executor.space.ISearchSpaceExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.ITranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.sql.ISpaceSqlTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.space.Space;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.SpaceSearchCriterion;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
@Component
public class SearchSpaceSqlMethodExecutor extends AbstractSearchMethodExecutor<Space, Long, SpaceSearchCriterion, SpaceFetchOptions> implements
ISearchSpaceMethodExecutor
{
@Autowired
private ISearchSpaceExecutor searchExecutor;
@Autowired
private ISpaceSqlTranslator translator;
@Override
protected ISearchObjectExecutor<SpaceSearchCriterion, Long> getSearchExecutor()
{
return new ISearchObjectExecutor<SpaceSearchCriterion, Long>()
{
@Override
public List<Long> search(IOperationContext context, SpaceSearchCriterion criterion)
{
List<SpacePE> spaces = searchExecutor.search(context, criterion);
List<Long> ids = new ArrayList<Long>();
for (SpacePE space : spaces)
{
ids.add(space.getId());
}
return ids;
}
};
}
@Override
protected ITranslator<Long, Space, SpaceFetchOptions> getTranslator()
{
return translator;
}
}
/*
* 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.common.sql.IObjectToManyRelationTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions;
/**
* @author pkupczyk
*/
public interface IObjectToProjectsSqlTranslator extends IObjectToManyRelationTranslator<Project, ProjectFetchOptions>
{
}
/*
* 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 java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectToManyRelationTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions;
/**
* @author pkupczyk
*/
public abstract class ObjectToProjectsSqlTranslator extends ObjectToManyRelationTranslator<Project, ProjectFetchOptions> implements
IObjectToProjectsSqlTranslator
{
@Autowired
private IProjectSqlTranslator projectTranslator;
@Override
protected Map<Long, Project> translateRelated(TranslationContext context, Collection<Long> relatedIds, ProjectFetchOptions relatedFetchOptions)
{
return projectTranslator.translate(context, relatedIds, relatedFetchOptions);
}
@Override
protected Collection<Project> createCollection()
{
return new ArrayList<Project>();
}
}
/*
* 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 java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
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.project.IProjectTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IProjectDAO;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
/**
* @author pkupczyk
*/
@Component
public class ProjectSqlTranslator implements IProjectSqlTranslator
{
@Autowired
private IDAOFactory daoFactory;
@Autowired
private IProjectTranslator projectTranslator;
@Override
public Project translate(TranslationContext context, Long object, ProjectFetchOptions fetchOptions)
{
return translate(context, Collections.singleton(object), fetchOptions).get(object);
}
@Override
public Map<Long, Project> translate(TranslationContext context, Collection<Long> objects, ProjectFetchOptions fetchOptions)
{
IProjectDAO projectDao = daoFactory.getProjectDAO();
List<ProjectPE> projects = projectDao.listByIDs(objects);
Map<ProjectPE, Project> peMap = projectTranslator.translate(context, projects, fetchOptions);
Map<Long, Project> idMap = new LinkedHashMap<Long, Project>();
for (Map.Entry<ProjectPE, Project> entry : peMap.entrySet())
{
idMap.put(entry.getKey().getId(), entry.getValue());
}
return idMap;
}
}
/*
* 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.space.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.IObjectAuthorizationValidator;
/**
* @author pkupczyk
*/
public interface ISpaceAuthorizationSqlValidator extends IObjectAuthorizationValidator
{
}
/*
* 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.space.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.IObjectBaseTranslator;
/**
* @author pkupczyk
*/
public interface ISpaceBaseSqlTranslator extends IObjectBaseTranslator<SpaceBaseRecord>
{
}
/*
* 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.space.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project.sql.IObjectToProjectsSqlTranslator;
/**
* @author pkupczyk
*/
public interface ISpaceProjectSqlTranslator extends IObjectToProjectsSqlTranslator
{
}
/*
* 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.space.sql;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.sql.IObjectToPersonSqlTranslator;
/**
* @author pkupczyk
*/
public interface ISpaceRegistratorSqlTranslator extends IObjectToPersonSqlTranslator
{
}
/*
* 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.space.sql;
/**
* @author pkupczyk
*/
public class SpaceAuthorizationRecord
{
public Long id;
public String code;
}
/*
* 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.space.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import net.lemnik.eodsql.QueryTool;
import org.springframework.stereotype.Component;
import ch.systemsx.cisd.openbis.generic.server.authorization.validator.SimpleSpaceValidator;
import ch.systemsx.cisd.openbis.generic.shared.basic.ICodeHolder;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
/**
* @author pkupczyk
*/
@Component
public class SpaceAuthorizationSqlValidator implements ISpaceAuthorizationSqlValidator
{
@Override
public Collection<Long> validate(PersonPE person, Collection<Long> spaceIds)
{
SpaceQuery query = QueryTool.getManagedQuery(SpaceQuery.class);
List<SpaceAuthorizationRecord> records = query.getAuthorizations(new LongOpenHashSet(spaceIds));
SimpleSpaceValidator validator = new SimpleSpaceValidator();
List<Long> result = new LinkedList<Long>();
for (SpaceAuthorizationRecord record : records)
{
final SpaceAuthorizationRecord theRecord = record;
if (validator.doValidation(person, new ICodeHolder()
{
@Override
public String getCode()
{
return theRecord.code;
}
}))
{
result.add(record.id);
}
}
return result;
}
}
/*
* 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.space.sql;
import java.util.Date;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectBaseRecord;
/**
* @author pkupczyk
*/
public class SpaceBaseRecord extends ObjectBaseRecord
{
public String code;
public String description;
public Date registrationDate;
}
/*
* 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.space.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.List;
import net.lemnik.eodsql.QueryTool;
import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.common.sql.ObjectBaseTranslator;
/**
* @author pkupczyk
*/
@Component
public class SpaceBaseSqlTranslator extends ObjectBaseTranslator<SpaceBaseRecord> implements ISpaceBaseSqlTranslator
{
@Override
protected List<SpaceBaseRecord> loadRecords(LongOpenHashSet objectIds)
{
SpaceQuery query = QueryTool.getManagedQuery(SpaceQuery.class);
return query.getSpaces(new LongOpenHashSet(objectIds));
}
}
\ No newline at end of file
/*
* 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.space.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.List;
import org.springframework.stereotype.Component;
import net.lemnik.eodsql.QueryTool;
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.project.sql.ObjectToProjectsSqlTranslator;
/**
* @author pkupczyk
*/
@Component
public class SpaceProjectSqlTranslator extends ObjectToProjectsSqlTranslator implements ISpaceProjectSqlTranslator
{
@Override
protected List<ObjectRelationRecord> loadRecords(LongOpenHashSet objectIds)
{
SpaceQuery query = QueryTool.getManagedQuery(SpaceQuery.class);
return query.getProjectIds(objectIds);
}
}
......@@ -32,7 +32,19 @@ import ch.systemsx.cisd.common.db.mapper.LongSetMapper;
public interface SpaceQuery extends ObjectQuery
{
@Select(sql = "select s.id, s.code from spaces s where s.id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<SpaceAuthorizationRecord> getAuthorizations(LongSet spaceIds);
@Select(sql = "select s.id, s.code, s.description, s.registration_timestamp as registrationDate from spaces s where s.id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<SpaceBaseRecord> getSpaces(LongSet spaceIds);
@Select(sql = "select s.space_id as objectId, s.id as relatedId from samples s where s.space_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getSampleIds(LongSet spaceIds);
@Select(sql = "select s.id as objectId, s.pers_id_registerer as relatedId from spaces s where s.id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getRegistratorIds(LongSet spaceIds);
@Select(sql = "select p.space_id as objectId, p.id as relatedId from projects p where p.space_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE)
public List<ObjectRelationRecord> getProjectIds(LongSet spaceIds);
}
/*
* 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.space.sql;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.List;
import net.lemnik.eodsql.QueryTool;
import org.springframework.stereotype.Component;
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.person.sql.ObjectToPersonSqlTranslator;
/**
* @author pkupczyk
*/
@Component
public class SpaceRegistratorSqlTranslator extends ObjectToPersonSqlTranslator implements ISpaceRegistratorSqlTranslator
{
@Override
protected List<ObjectRelationRecord> loadRecords(LongOpenHashSet objectIds)
{
SpaceQuery query = QueryTool.getManagedQuery(SpaceQuery.class);
return query.getRegistratorIds(objectIds);
}
}
......@@ -17,54 +17,112 @@
package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.sql;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
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.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.ISpaceTranslator;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationResults;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.space.Space;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.SpacePermId;
/**
* @author pkupczyk
*/
@Component
public class SpaceSqlTranslator implements ISpaceSqlTranslator
public class SpaceSqlTranslator extends AbstractCachingTranslator<Long, Space, SpaceFetchOptions> implements ISpaceSqlTranslator
{
@Autowired
private ISpaceTranslator spaceTranslator;
private ISpaceAuthorizationSqlValidator authorizationValidator;
@Autowired
private IDAOFactory daoFactory;
private ISpaceRegistratorSqlTranslator registratorTranslator;
@Autowired
private ISpaceProjectSqlTranslator projectTranslator;
@Autowired
private ISpaceSampleSqlTranslator sampleTranslator;
@Autowired
private ISpaceBaseSqlTranslator baseTranslator;
@Override
protected Collection<Long> shouldTranslate(TranslationContext context, Collection<Long> spaceIds, SpaceFetchOptions fetchOptions)
{
return authorizationValidator.validate(context.getSession().tryGetPerson(), spaceIds);
}
@Override
public Space translate(TranslationContext context, Long spaceId, SpaceFetchOptions fetchOptions)
protected Space createObject(TranslationContext context, Long spaceId, SpaceFetchOptions fetchOptions)
{
return translate(context, Collections.singletonList(spaceId), fetchOptions).get(spaceId);
Space space = new Space();
space.setFetchOptions(new SpaceFetchOptions());
return space;
}
@Override
public Map<Long, Space> translate(TranslationContext context, Collection<Long> spaceIds, SpaceFetchOptions fetchOptions)
protected Object getObjectsRelations(TranslationContext context, Collection<Long> spaceIds, SpaceFetchOptions fetchOptions)
{
List<SpacePE> spaces = daoFactory.getSpaceDAO().listByIDs(spaceIds);
TranslationResults relations = new TranslationResults();
relations.put(ISpaceBaseSqlTranslator.class, baseTranslator.translate(context, spaceIds, null));
if (fetchOptions.hasProjects())
{
relations.put(ISpaceProjectSqlTranslator.class, projectTranslator.translate(context, spaceIds, fetchOptions.withProjects()));
}
Map<SpacePE, Space> spacePeToSpace = spaceTranslator.translate(context, spaces, fetchOptions);
Map<Long, Space> spaceIdToSpace = new HashMap<Long, Space>();
if (fetchOptions.hasSamples())
{
relations.put(ISpaceSampleSqlTranslator.class, sampleTranslator.translate(context, spaceIds, fetchOptions.withSamples()));
}
if (fetchOptions.hasRegistrator())
{
relations.put(ISpaceRegistratorSqlTranslator.class, registratorTranslator.translate(context, spaceIds, fetchOptions.withRegistrator()));
}
return relations;
}
@Override
protected void updateObject(TranslationContext context, Long spaceId, Space result, Object objectRelations, SpaceFetchOptions fetchOptions)
{
TranslationResults relations = (TranslationResults) objectRelations;
SpaceBaseRecord baseRecord = relations.get(ISpaceBaseSqlTranslator.class, spaceId);
result.setCode(baseRecord.code);
result.setPermId(new SpacePermId(baseRecord.code));
result.setDescription(baseRecord.description);
// TODO: add modification date to spaces table
result.setModificationDate(baseRecord.registrationDate);
result.setRegistrationDate(baseRecord.registrationDate);
if (fetchOptions.hasProjects())
{
result.setProjects((List<Project>) relations.get(ISpaceProjectSqlTranslator.class, spaceId));
result.getFetchOptions().withProjectsUsing(fetchOptions.withProjects());
}
if (fetchOptions.hasSamples())
{
result.setSamples((List<Sample>) relations.get(ISpaceSampleSqlTranslator.class, spaceId));
result.getFetchOptions().withSamplesUsing(fetchOptions.withSamples());
}
for (SpacePE space : spaces)
if (fetchOptions.hasRegistrator())
{
spaceIdToSpace.put(space.getId(), spacePeToSpace.get(space));
result.setRegistrator(relations.get(ISpaceRegistratorSqlTranslator.class, spaceId));
result.getFetchOptions().withRegistratorUsing(fetchOptions.withRegistrator());
}
return spaceIdToSpace;
}
}
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