use of com.thoughtworks.go.server.ui.ModificationForPipeline in project gocd by gocd.
the class ChangesetService method modificationsOfPipelines.
public Map<Long, List<ModificationForPipeline>> modificationsOfPipelines(List<Long> pipelineIds, String pipelineName, Username username) {
Map<Long, List<ModificationForPipeline>> modificationsForPipelineIds = materialRepository.findModificationsForPipelineIds(pipelineIds);
PipelineConfigDependencyGraph graph = goConfigService.upstreamDependencyGraphOf(pipelineName);
Set<String> allMaterialFingerprints = graph.allMaterialFingerprints();
Set<String> reachableMaterialfingerprints = populateReachableFingerprints(graph, username, true, true);
FingerprintLoader<ModificationForPipeline> loader = new FingerprintLoader<ModificationForPipeline>() {
public String getFingerprint(ModificationForPipeline modificationForPipeline) {
return modificationForPipeline.getMaterialFingerprint();
}
};
for (Map.Entry<Long, List<ModificationForPipeline>> pipelineIdAndModifications : modificationsForPipelineIds.entrySet()) {
List<ModificationForPipeline> visibleModifications = filterFingerprintHolders(pipelineIdAndModifications.getValue(), reachableMaterialfingerprints, allMaterialFingerprints, loader);
pipelineIdAndModifications.setValue(visibleModifications);
}
return modificationsForPipelineIds;
}
use of com.thoughtworks.go.server.ui.ModificationForPipeline 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.ModificationForPipeline in project gocd by gocd.
the class StageService method populateAuthorsAndMingleCards.
private void populateAuthorsAndMingleCards(List<StageFeedEntry> stageEntries, String pipelineName, Username username) {
List<Long> pipelineIds = new ArrayList<>();
for (StageFeedEntry stageEntry : stageEntries) {
pipelineIds.add(stageEntry.getPipelineId());
}
CruiseConfig config = goConfigService.currentCruiseConfig();
Map<Long, List<ModificationForPipeline>> revisionsPerPipeline = changesetService.modificationsOfPipelines(pipelineIds, pipelineName, username);
for (StageFeedEntry stageEntry : stageEntries) {
List<ModificationForPipeline> revs = revisionsPerPipeline.get(stageEntry.getPipelineId());
for (ModificationForPipeline rev : revs) {
Author author = rev.getAuthor();
if (author != null) {
stageEntry.addAuthor(author);
}
String pipelineForRev = rev.getPipelineId().getPipelineName();
if (config.hasPipelineNamed(new CaseInsensitiveString(pipelineForRev))) {
PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineForRev));
MingleConfig mingleConfig = pipelineConfig.getMingleConfig();
Set<String> cardNos = rev.getCardNumbersFromComments();
if (mingleConfig.isDefined()) {
for (String cardNo : cardNos) {
stageEntry.addCard(new MingleCard(mingleConfig, cardNo));
}
}
} else {
LOGGER.debug("pipeline not found: {}", pipelineForRev);
}
}
}
}
Aggregations