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));
}
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));
}
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;
}
}
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));
}
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));
}
Aggregations