Search in sources :

Example 1 with ModificationForPipeline

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;
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) ModificationForPipeline(com.thoughtworks.go.server.ui.ModificationForPipeline) ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ModificationForPipeline

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;
        }
    });
}
Also used : LongType(org.hibernate.type.LongType) StringType(org.hibernate.type.StringType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PipelineId(com.thoughtworks.go.server.ui.PipelineId) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) ModificationForPipeline(com.thoughtworks.go.server.ui.ModificationForPipeline) CollectionUtil(com.thoughtworks.go.server.util.CollectionUtil)

Example 3 with ModificationForPipeline

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);
            }
        }
    }
}
Also used : ModificationForPipeline(com.thoughtworks.go.server.ui.ModificationForPipeline) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) MingleCard(com.thoughtworks.go.server.ui.MingleCard) Author(com.thoughtworks.go.domain.feed.Author)

Aggregations

ModificationForPipeline (com.thoughtworks.go.server.ui.ModificationForPipeline)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 Author (com.thoughtworks.go.domain.feed.Author)1 StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)1 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)1 MingleCard (com.thoughtworks.go.server.ui.MingleCard)1 PipelineId (com.thoughtworks.go.server.ui.PipelineId)1 CollectionUtil (com.thoughtworks.go.server.util.CollectionUtil)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 LongType (org.hibernate.type.LongType)1 StringType (org.hibernate.type.StringType)1 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)1