use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method create.
public final ActionResponse<JobFieldModel> create(JobFieldModel resource) {
boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasCreatePermission);
if (!hasPermissions) {
return ActionResponse.createForbiddenResponse();
}
// Clean input
resource.setJobId(null);
correctProjectsField(resource);
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
}
return createWithoutChecks(resource);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createErrorResponse.
private ActionResponse<OAuthEndpointResponse> createErrorResponse(HttpStatus httpStatus, String errorMessage) {
oAuthRequestValidator.removeAllRequests();
OAuthEndpointResponse oAuthEndpointResponse = new OAuthEndpointResponse(false, "", errorMessage);
return new ActionResponse<>(httpStatus, errorMessage, oAuthEndpointResponse);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<OAuthEndpointResponse> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
try {
Optional<FieldModel> savedFieldModel = saveIfValid(fieldModel);
if (!savedFieldModel.isPresent()) {
return createErrorResponse("The configuration is invalid. Please test the configuration.");
}
FieldUtility fieldUtility = createFieldAccessor(savedFieldModel.get());
Optional<String> clientId = fieldUtility.getString(AzureBoardsDescriptor.KEY_CLIENT_ID);
if (!clientId.isPresent()) {
return createErrorResponse("App ID not found.");
}
Optional<String> alertServerUrl = alertWebServerUrlManager.getServerUrl();
if (!alertServerUrl.isPresent()) {
return createErrorResponse("Could not determine the alert server url for the callback.");
}
String requestKey = oAuthRequestValidator.generateRequestKey();
// since we have only one OAuth channel now remove any other requests.
// if we have more OAuth clients then the "remove requests" will have to be removed from here.
// beginning authentication process create the request id at the start.
oAuthRequestValidator.removeRequestsOlderThan5MinutesAgo();
oAuthRequestValidator.addAuthorizationRequest(requestKey);
logger.info("OAuth authorization request created: {}", requestKey);
String authUrl = createAuthURL(clientId.get(), requestKey);
logger.debug("Authenticating Azure OAuth URL: {}", authUrl);
return new ActionResponse<>(HttpStatus.OK, new OAuthEndpointResponse(isAuthenticated(fieldUtility), authUrl, "Authenticating..."));
} catch (Exception ex) {
logger.error("Error activating Azure Boards", ex);
return createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, "Error activating azure oauth.");
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class JobConfigActions method createWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
try {
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
configurationFieldModels.addAll(savedFieldsModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project hub-alert by blackducksoftware.
the class JobConfigActions method deleteWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> deleteWithoutChecks(UUID id) {
try {
Optional<DistributionJobModel> job = jobAccessor.getJobById(id);
if (job.isPresent()) {
LinkedList<FieldModel> processedFieldModels = new LinkedList<>();
DistributionJobModel distributionJobModel = job.get();
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
for (FieldModel fieldModel : jobFieldModel.getFieldModels()) {
FieldModel preProcessedFieldModel = fieldModelProcessor.performBeforeDeleteAction(fieldModel);
processedFieldModels.add(preProcessedFieldModel);
}
jobAccessor.deleteJob(distributionJobModel.getJobId());
for (FieldModel preProcessedFieldModel : processedFieldModels) {
fieldModelProcessor.performAfterDeleteAction(preProcessedFieldModel);
}
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
} catch (AlertException ex) {
logger.error("Error reading job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Aggregations