use of com.thoughtworks.go.server.ui.PipelineId in project gocd by gocd.
the class MaterialRepository method findModificationsForPipelineIds.
public Map<Long, List<ModificationForPipeline>> findModificationsForPipelineIds(final List<Long> pipelineIds) {
final int MODIFICATION = 0;
final int RELEVANT_PIPELINE_ID = 1;
final int RELEVANT_PIPELINE_NAME = 2;
final int MATERIAL_TYPE = 3;
final int MATERIAL_FINGERPRINT = 4;
// noinspection unchecked
return (Map<Long, List<ModificationForPipeline>>) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
if (pipelineIds.isEmpty()) {
return new HashMap<Long, List<ModificationForPipeline>>();
}
Map<PipelineId, Set<Long>> relevantToLookedUpMap = relevantToLookedUpDependencyMap(session, pipelineIds);
SQLQuery query = session.createSQLQuery("SELECT mods.*, pmr.pipelineId as pmrPipelineId, p.name as pmrPipelineName, m.type as materialType, m.fingerprint as fingerprint" + " FROM modifications mods " + " INNER JOIN pipelineMaterialRevisions pmr ON (mods.id >= pmr.fromRevisionId AND mods.id <= pmr.toRevisionId) AND mods.materialId = pmr.materialId " + " INNER JOIN pipelines p ON pmr.pipelineId = p.id" + " INNER JOIN materials m ON mods.materialId = m.id" + " WHERE pmr.pipelineId IN (:ids)");
@SuppressWarnings({ "unchecked" }) List<Object[]> allModifications = query.addEntity("mods", Modification.class).addScalar("pmrPipelineId", new LongType()).addScalar("pmrPipelineName", new StringType()).addScalar("materialType", new StringType()).addScalar("fingerprint", new StringType()).setParameterList("ids", CollectionUtil.map(relevantToLookedUpMap.keySet(), PipelineId.MAP_ID)).list();
Map<Long, List<ModificationForPipeline>> modificationsForPipeline = new HashMap<>();
CollectionUtil.CollectionValueMap<Long, ModificationForPipeline> modsForPipeline = CollectionUtil.collectionValMap(modificationsForPipeline, new CollectionUtil.ArrayList<>());
for (Object[] modAndPmr : allModifications) {
Modification mod = (Modification) modAndPmr[MODIFICATION];
Long relevantPipelineId = (Long) modAndPmr[RELEVANT_PIPELINE_ID];
String relevantPipelineName = (String) modAndPmr[RELEVANT_PIPELINE_NAME];
String materialType = (String) modAndPmr[MATERIAL_TYPE];
String materialFingerprint = (String) modAndPmr[MATERIAL_FINGERPRINT];
PipelineId relevantPipeline = new PipelineId(relevantPipelineName, relevantPipelineId);
Set<Long> longs = relevantToLookedUpMap.get(relevantPipeline);
for (Long lookedUpPipeline : longs) {
modsForPipeline.put(lookedUpPipeline, new ModificationForPipeline(relevantPipeline, mod, materialType, materialFingerprint));
}
}
return modificationsForPipeline;
}
});
}
use of com.thoughtworks.go.server.ui.PipelineId in project gocd by gocd.
the class MaterialRepository method relevantToLookedUpDependencyMap.
private Map<PipelineId, Set<Long>> relevantToLookedUpDependencyMap(Session session, List<Long> pipelineIds) {
final int LOOKED_UP_PIPELINE_ID = 2;
final int RELEVANT_PIPELINE_ID = 0;
final int RELEVANT_PIPELINE_NAME = 1;
String pipelineIdsSql = queryExtensions.queryRelevantToLookedUpDependencyMap(pipelineIds);
SQLQuery pipelineIdsQuery = session.createSQLQuery(pipelineIdsSql);
pipelineIdsQuery.addScalar("id", new LongType());
pipelineIdsQuery.addScalar("name", new StringType());
pipelineIdsQuery.addScalar("lookedUpId", new LongType());
final List<Object[]> ids = pipelineIdsQuery.list();
Map<Long, List<PipelineId>> lookedUpToParentMap = new HashMap<>();
CollectionUtil.CollectionValueMap<Long, PipelineId> lookedUpToRelevantMap = CollectionUtil.collectionValMap(lookedUpToParentMap, new CollectionUtil.ArrayList<>());
for (Object[] relevantAndLookedUpId : ids) {
lookedUpToRelevantMap.put((Long) relevantAndLookedUpId[LOOKED_UP_PIPELINE_ID], new PipelineId((String) relevantAndLookedUpId[RELEVANT_PIPELINE_NAME], (Long) relevantAndLookedUpId[RELEVANT_PIPELINE_ID]));
}
return CollectionUtil.reverse(lookedUpToParentMap);
}
Aggregations