use of com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo in project gocd by gocd.
the class InternalMaterialsControllerV1 method createMergedMap.
private Map<MaterialConfig, MaterialInfo> createMergedMap(Map<MaterialConfig, Boolean> materialConfigs, Map<String, Modification> modificationsMap, Collection<MaintenanceModeService.MaterialPerformingMDU> runningMDUs, ServerHealthStates allLogs) {
HashMap<MaterialConfig, MaterialInfo> map = new HashMap<>();
if (materialConfigs.isEmpty()) {
return map;
}
materialConfigs.forEach((materialConfig, hasOperatePermission) -> {
if (!materialConfig.getType().equals(DependencyMaterialConfig.TYPE)) {
Material material = materialConfigConverter.toMaterial(materialConfig);
List<HealthStateScope> scopes = asList(forMaterial(material), forMaterialUpdate(material), forMaterialConfig(materialConfig));
List<ServerHealthState> logs = allLogs.stream().filter((log) -> scopes.contains(log.getType().getScope())).collect(toList());
Modification mod = modificationsMap.getOrDefault(materialConfig.getFingerprint(), null);
MaintenanceModeService.MaterialPerformingMDU mduInfo = runningMDUs.stream().filter((mdu) -> mdu.getMaterial().getFingerprint().equals(materialConfig.getFingerprint())).findFirst().orElse(null);
boolean isMDUInProgress = mduInfo != null;
Timestamp updateStartTime = isMDUInProgress ? mduInfo.getTimestamp() : null;
map.put(materialConfig, new MaterialInfo(mod, hasOperatePermission, isMDUInProgress, updateStartTime, logs));
}
});
return map;
}
use of com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo in project gocd by gocd.
the class InternalMaterialsControllerV1 method index.
public String index(Request request, Response response) throws Exception {
Map<MaterialConfig, Boolean> materialConfigs = materialConfigService.getMaterialConfigsWithPermissions(currentUsernameString());
Map<String, Modification> modifications = materialService.getLatestModificationForEachMaterial();
Collection<MaintenanceModeService.MaterialPerformingMDU> runningMDUs = maintenanceModeService.getRunningMDUs();
ServerHealthStates logs = serverHealthService.logs();
Map<MaterialConfig, MaterialInfo> mergedMap = createMergedMap(materialConfigs, modifications, runningMDUs, logs);
final String etag = etagFor(mergedMap);
if (fresh(request, etag)) {
return notModified(response);
}
setEtagHeader(response, etag);
return writerForTopLevelObject(request, response, writer -> MaterialWithModificationsRepresenter.toJSON(writer, mergedMap));
}
Aggregations