Search in sources :

Example 21 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class ModificationsTest method shouldUnderstandIfContainsModificationWithSameRevision.

@Test
public void shouldUnderstandIfContainsModificationWithSameRevision() {
    MaterialInstance materialInstance = MaterialsMother.hgMaterial().createMaterialInstance();
    final Modification modification = modificationWith(materialInstance, "1");
    final Modification sameModification = modificationWith(materialInstance, "1");
    final Modification modificationWithDifferentRev = modificationWith(materialInstance, "2");
    final Modification modificationWithDifferentMaterial = modificationWith(MaterialsMother.hgMaterial("http://foo.com").createMaterialInstance(), "1");
    Modifications modifications = new Modifications(modification);
    assertThat(modifications.containsRevisionFor(modification), is(true));
    assertThat(modifications.containsRevisionFor(sameModification), is(true));
    assertThat(modifications.containsRevisionFor(modificationWithDifferentRev), is(false));
    //note that its checking for revision and not material instance
    assertThat(modifications.containsRevisionFor(modificationWithDifferentMaterial), is(true));
}
Also used : MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Test(org.junit.Test)

Example 22 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class PluggableSCMMaterialPoller method latestModification.

@Override
public List<Modification> latestModification(final PluggableSCMMaterial material, File baseDir, SubprocessExecutionContext execCtx) {
    SCMPropertyConfiguration scmPropertyConfiguration = buildSCMPropertyConfigurations(material.getScmConfig());
    final MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
    MaterialPollResult pollResult = scmExtension.getLatestRevision(material.getPluginId(), scmPropertyConfiguration, materialInstance.getAdditionalDataMap(), baseDir.getAbsolutePath());
    final Map<String, String> materialData = pollResult.getMaterialData();
    if (materialInstance.requiresUpdate(materialData)) {
        updateAdditionalData(materialInstance.getId(), materialData);
    }
    SCMRevision scmRevision = pollResult.getLatestRevision();
    return scmRevision == null ? new Modifications() : new Modifications(getModification(scmRevision));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Example 23 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class ValueStreamMapService method getValueStreamMap.

public ValueStreamMapPresentationModel getValueStreamMap(String materialFingerprint, String revision, Username username, LocalizedOperationResult result) {
    try {
        MaterialConfig materialConfig = null;
        boolean hasViewPermissionForMaterial = false;
        List<PipelineConfig> downstreamPipelines = new ArrayList<>();
        for (PipelineConfigs pipelineGroup : goConfigService.groups()) {
            boolean hasViewPermissionForGroup = securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), pipelineGroup.getGroup());
            for (PipelineConfig pipelineConfig : pipelineGroup) {
                for (MaterialConfig currentMaterialConfig : pipelineConfig.materialConfigs()) {
                    if (currentMaterialConfig.getFingerprint().equals(materialFingerprint)) {
                        materialConfig = currentMaterialConfig;
                        if (hasViewPermissionForGroup) {
                            hasViewPermissionForMaterial = true;
                        }
                        downstreamPipelines.add(pipelineConfig);
                    }
                }
            }
        }
        if (materialConfig == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.GLOBAL));
            return null;
        }
        if (!hasViewPermissionForMaterial) {
            result.unauthorized(LocalizedMessage.cannotViewMaterial(materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        MaterialInstance materialInstance = materialRepository.findMaterialInstance(materialConfig);
        if (materialInstance == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        Material material = new MaterialConfigConverter().toMaterial(materialConfig);
        Modification modification = materialRepository.findModificationWithRevision(material, revision);
        if (modification == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_MODIFICATION_NOT_FOUND", materialFingerprint, revision), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        ValueStreamMap valueStreamMap = buildValueStreamMap(material, materialInstance, modification, downstreamPipelines, username);
        if (valueStreamMap == null) {
            return null;
        }
        return valueStreamMap.presentationModel();
    } catch (Exception e) {
        result.internalServerError(LocalizedMessage.string("VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL", materialFingerprint, revision));
        LOGGER.error(String.format("[Value Stream Map] Material %s with revision %s could not be rendered.", materialFingerprint, revision), e);
        return null;
    }
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ArrayList(java.util.ArrayList) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Example 24 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class ModificationIntegrationTest method shouldPersistAdditionalDataIntoModificationsTable.

@Test
public void shouldPersistAdditionalDataIntoModificationsTable() throws Exception {
    String revision = "revision";
    HashMap<String, String> additionalDataMap = new HashMap<>();
    additionalDataMap.put("key", "value");
    String additionalData = JsonHelper.toJsonString(additionalDataMap);
    final Modification modification = new Modification("user", "comment", "foo@bar.fooadsf", new Date(), revision, additionalData);
    final GitMaterial git = new GitMaterial("url", "branch");
    transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) throws Exception {
            MaterialInstance gitInstance = materialRepository.findOrCreateFrom(git);
            materialRepository.saveModification(gitInstance, modification);
            return null;
        }
    });
    Modification actual = materialRepository.findModificationWithRevision(git, revision);
    /*
            Checking if time are the same, because actual has SQLTime whereas we send in java.util.Date. No idea how we were testing this ever
            because Modification#equals fails instance check (ShilpaG & Sachin)
         */
    assertThat(actual.getModifiedTime().getTime(), is(modification.getModifiedTime().getTime()));
    assertThat(actual.getAdditionalData(), is(additionalData));
    assertThat(actual.getAdditionalDataMap(), is(additionalDataMap));
}
Also used : TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Date(java.util.Date) Test(org.junit.Test)

Example 25 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class TfsMaterialPersistenceTest method shouldFindOldMaterial.

@Test
public void shouldFindOldMaterial() {
    TfsMaterial tfsCfg = new TfsMaterial(new GoCipher(), new UrlArgument("url"), "loser", "CORPORATE", "foo_bar_baz", "/dev/null");
    MaterialInstance tfsInstance1 = materialRepository.findOrCreateFrom(tfsCfg);
    goCache.clear();
    MaterialInstance tfsInstance2 = materialRepository.findOrCreateFrom(tfsCfg);
    assertThat(tfsInstance1, is(tfsInstance2));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) GoCipher(com.thoughtworks.go.security.GoCipher) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Test(org.junit.Test)

Aggregations

MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)39 Test (org.junit.Test)28 File (java.io.File)13 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 Modification (com.thoughtworks.go.domain.materials.Modification)9 Modifications (com.thoughtworks.go.domain.materials.Modifications)9 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)7 MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)7 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)6 Date (java.util.Date)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)5 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 TfsMaterial (com.thoughtworks.go.config.materials.tfs.TfsMaterial)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)4 Material (com.thoughtworks.go.domain.materials.Material)4 HashMap (java.util.HashMap)4