Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump loader-utils from 2.0.3 to 2.0.4 in /react-frontend #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ private String toStringRepresentation(HttpRequest httpRequest)
httpRequest.getHttpMethod(),
httpRequest.getUrl(),
httpRequestHeaders,
httpRequest.getRequestBody());
httpRequest.getRequestBody())
.trim();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Optional;
import java.util.stream.Collectors;

import de.captaingoldfish.scim.sdk.common.exceptions.BadRequestException;
import org.apache.commons.lang3.StringUtils;

import de.captaingoldfish.restclient.application.utils.Utils;
Expand All @@ -16,7 +15,7 @@
import de.captaingoldfish.restclient.database.repositories.HttpRequestsDao;
import de.captaingoldfish.restclient.scim.resources.ScimHttpRequest;
import de.captaingoldfish.scim.sdk.common.constants.enums.SortOrder;
import de.captaingoldfish.scim.sdk.common.exceptions.InternalServerException;
import de.captaingoldfish.scim.sdk.common.exceptions.BadRequestException;
import de.captaingoldfish.scim.sdk.common.exceptions.ResourceNotFoundException;
import de.captaingoldfish.scim.sdk.common.schemas.SchemaAttribute;
import de.captaingoldfish.scim.sdk.server.endpoints.Context;
Expand Down Expand Up @@ -48,7 +47,10 @@ public ScimHttpRequest createResource(ScimHttpRequest resource, Context context)
{
try
{
HttpRequest httpRequest = HttpRequestsConverter.toHttpRequest(resource,
Optional<HttpRequest> optionalHttpRequest = httpRequestsDao.findByName(resource.getName());
HttpRequest httpRequest = HttpRequestsConverter.toHttpRequest(optionalHttpRequest.map(HttpRequest::getId)
.orElse(0L),
resource,
httpRequestsDao,
httpRequestCategoriesDao);
HttpResponse httpResponse = sendHttpRequest(httpRequest);
Expand All @@ -62,7 +64,7 @@ public ScimHttpRequest createResource(ScimHttpRequest resource, Context context)
}
catch (Exception ex)
{
throw new BadRequestException(ex.getMessage());
throw new BadRequestException(ex.getMessage(), ex);
}
}

Expand Down Expand Up @@ -98,8 +100,8 @@ public PartialListResponse<ScimHttpRequest> listResources(long startIndex,
Context context)
{
List<HttpRequest> httpRequest = httpRequestsDao.findAll();
List<ScimHttpRequest> scimHttpRequest = httpRequest.stream().map(category -> {
return HttpRequestsConverter.toScimHttpRequest(category, null);
List<ScimHttpRequest> scimHttpRequest = httpRequest.stream().map(request -> {
return HttpRequestsConverter.toScimHttpRequest(request, null);
}).collect(Collectors.toList());
return PartialListResponse.<ScimHttpRequest> builder()
.resources(new ArrayList<>())
Expand All @@ -121,14 +123,20 @@ public ScimHttpRequest updateResource(ScimHttpRequest resource, Context context)
throw new ResourceNotFoundException(String.format("HTTP request with id '%s' does not exist", dbId));
}

HttpRequest updatedHttpRequest = HttpRequestsConverter.toHttpRequest(resource,
HttpRequest updatedHttpRequest = HttpRequestsConverter.toHttpRequest(dbId,
resource,
httpRequestsDao,
httpRequestCategoriesDao);
updatedHttpRequest.setCreated(httpRequest.getCreated());
updatedHttpRequest.setLastModified(Instant.now());
HttpResponse httpResponse = sendHttpRequest(updatedHttpRequest);
addToHistory(updatedHttpRequest, httpResponse);
httpRequest = httpRequestsDao.save(httpRequest);
boolean sendHttpRequest = httpRequest.getName().equals(resource.getName());
HttpResponse httpResponse = null;
if (sendHttpRequest)
{
httpResponse = sendHttpRequest(updatedHttpRequest);
addToHistory(updatedHttpRequest, httpResponse);
}
httpRequest = httpRequestsDao.save(updatedHttpRequest);

return HttpRequestsConverter.toScimHttpRequest(httpRequest, httpResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.commons.lang3.StringUtils;

import de.captaingoldfish.restclient.application.endpoints.httpclient.HttpClientSettingsConverter;
import de.captaingoldfish.restclient.application.utils.Utils;
import de.captaingoldfish.restclient.database.entities.HttpClientSettings;
import de.captaingoldfish.restclient.database.entities.HttpHeader;
import de.captaingoldfish.restclient.database.entities.HttpRequest;
Expand Down Expand Up @@ -69,7 +68,14 @@ public static ScimHttpRequest toScimHttpRequest(HttpRequest httpRequest, HttpRes
.url(httpRequest.getUrl())
.requestHeaders(headers)
.requestBody(httpRequest.getRequestBody())
.responseStatus(String.valueOf(httpResponse.getResponseStatus()))
.responseId(Optional.ofNullable(httpResponse)
.map(HttpResponse::getId)
.map(String::valueOf)
.orElse(null))
.responseStatus(Optional.ofNullable(httpResponse)
.map(HttpResponse::getResponseStatus)
.map(String::valueOf)
.orElse(null))
.responseHeaders(httpHeaders)
.responseBody(Optional.ofNullable(httpResponse)
.map(HttpResponse::getResponseBody)
Expand All @@ -82,7 +88,8 @@ public static ScimHttpRequest toScimHttpRequest(HttpRequest httpRequest, HttpRes
.build();
}

public static HttpRequest toHttpRequest(ScimHttpRequest scimHttpRequest,
public static HttpRequest toHttpRequest(long resourceId,
ScimHttpRequest scimHttpRequest,
HttpRequestsDao httpRequestsDao,
HttpRequestCategoriesDao httpRequestCategoriesDao)
{
Expand All @@ -92,11 +99,9 @@ public static HttpRequest toHttpRequest(ScimHttpRequest scimHttpRequest,
List<HttpHeader> headers = scimHttpRequest.getRequestHeaders().stream().map(header -> {
return HttpHeader.builder().name(header.getName()).value(header.getValue()).build();
}).collect(Collectors.toList());
Optional<HttpRequest> optionalHttpRequest = httpRequestsDao.findById(scimHttpRequest.getId()
.map(Utils::parseId)
.orElse(0L));
Optional<HttpRequest> optionalHttpRequest = httpRequestsDao.findById(resourceId);
return HttpRequest.builder()
.id(scimHttpRequest.getId().map(Utils::parseId).orElse(0L))
.id(resourceId)
.name(scimHttpRequest.getName())
.httpClientSettings(clientSettings)
.httpRequestGroup(group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class OpenIdClientHandler extends ResourceHandler<ScimOpenIdClient>
{

/**
* to peform CRUD operations on OpenID Clients
* to perform CRUD operations on OpenID Clients
*/
private final OpenIdClientDao openIdClientDao;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package de.captaingoldfish.restclient.application.endpoints.responsehistory;

import java.util.ArrayList;
import java.util.List;

import de.captaingoldfish.restclient.database.entities.HttpRequest;
import de.captaingoldfish.restclient.database.entities.HttpResponse;
import de.captaingoldfish.restclient.scim.resources.ScimHttpResponseHistory;
import de.captaingoldfish.restclient.scim.resources.ScimHttpResponseHistory.ResponseHistory;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;


/**
* @author Pascal Knueppel
* @since 21.10.2022
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class HttpResponseConverter
{

public static ScimHttpResponseHistory toScimResponseHistory(HttpRequest httpRequest)
{
List<ResponseHistory> responseHistory = new ArrayList<>();

for ( HttpResponse httpResponse : httpRequest.getHttpResponses() )
{
responseHistory.add(ResponseHistory.builder()
.id(String.valueOf(httpResponse.getId()))
.status(httpResponse.getResponseStatus())
.originalRequest(httpResponse.getRequestDetails())
.responseHeaders(httpResponse.getResponseHeaders())
.responseBody(httpResponse.getResponseBody())
.created(httpResponse.getCreated())
.build());
}

return ScimHttpResponseHistory.builder()
.id(String.valueOf(httpRequest.getId()))
.groupName(httpRequest.getHttpRequestGroup().getName())
.requestName(httpRequest.getName())
.responseHistory(responseHistory)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package de.captaingoldfish.restclient.application.endpoints.responsehistory;

import java.util.List;

import de.captaingoldfish.restclient.application.utils.Utils;
import de.captaingoldfish.restclient.database.entities.HttpRequest;
import de.captaingoldfish.restclient.database.entities.HttpResponse;
import de.captaingoldfish.restclient.database.repositories.HttpRequestsDao;
import de.captaingoldfish.restclient.database.repositories.HttpResponseDao;
import de.captaingoldfish.restclient.scim.resources.ScimHttpResponseHistory;
import de.captaingoldfish.scim.sdk.common.constants.enums.SortOrder;
import de.captaingoldfish.scim.sdk.common.exceptions.NotImplementedException;
import de.captaingoldfish.scim.sdk.common.exceptions.ResourceNotFoundException;
import de.captaingoldfish.scim.sdk.common.schemas.SchemaAttribute;
import de.captaingoldfish.scim.sdk.server.endpoints.Context;
import de.captaingoldfish.scim.sdk.server.endpoints.ResourceHandler;
import de.captaingoldfish.scim.sdk.server.filter.FilterNode;
import de.captaingoldfish.scim.sdk.server.response.PartialListResponse;
import lombok.RequiredArgsConstructor;


/**
*
*/
@RequiredArgsConstructor
public class HttpResponseHistoryResourceHandler extends ResourceHandler<ScimHttpResponseHistory>
{

private final HttpRequestsDao httpRequestsDao;

private final HttpResponseDao httpResponseDao;

/**
* {@inheritDoc}
*/
@Override
public ScimHttpResponseHistory createResource(ScimHttpResponseHistory resource, Context context)
{
throw new NotImplementedException("Disabled endpoint");
}

/**
* {@inheritDoc}
*/
@Override
public ScimHttpResponseHistory getResource(String id,
List<SchemaAttribute> attributes,
List<SchemaAttribute> excludedAttributes,
Context context)
{
long databaseId = Utils.parseId(id);
HttpRequest httpRequest = httpRequestsDao.findById(databaseId).orElse(null);
if (httpRequest == null)
{
throw new ResourceNotFoundException(String.format("History could not be accessed because HTTP Request with id "
+ "'%s' does not exist",
id));
}
return HttpResponseConverter.toScimResponseHistory(httpRequest);
}

/**
* {@inheritDoc}
*/
@Override
public PartialListResponse<ScimHttpResponseHistory> listResources(long startIndex,
int count,
FilterNode filter,
SchemaAttribute sortBy,
SortOrder sortOrder,
List<SchemaAttribute> attributes,
List<SchemaAttribute> excludedAttributes,
Context context)
{
throw new NotImplementedException("Disabled endpoint");
}

/**
* {@inheritDoc}
*/
@Override
public ScimHttpResponseHistory updateResource(ScimHttpResponseHistory resource, Context context)
{
throw new NotImplementedException("Disabled endpoint");
}

/**
* {@inheritDoc}
*/
@Override
public void deleteResource(String id, Context context)
{
HttpResponse response = httpResponseDao.findById(id).orElse(null);
if (response == null)
{
throw new ResourceNotFoundException(String.format("HTTP Response with id '%s' does not exist", id));
}

httpResponseDao.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.captaingoldfish.restclient.application.endpoints.openidclient.OpenIdClientHandler;
import de.captaingoldfish.restclient.application.endpoints.openidprovider.OpenIdProviderHandler;
import de.captaingoldfish.restclient.application.endpoints.proxy.ProxyHandler;
import de.captaingoldfish.restclient.application.endpoints.responsehistory.HttpResponseHistoryResourceHandler;
import de.captaingoldfish.restclient.application.endpoints.tokencategory.TokenCategoryHandler;
import de.captaingoldfish.restclient.application.endpoints.tokenrequest.AccessTokenRequestHandler;
import de.captaingoldfish.restclient.application.endpoints.tokenstore.TokenStoreHandler;
Expand All @@ -29,6 +30,7 @@
import de.captaingoldfish.restclient.database.repositories.HttpClientSettingsDao;
import de.captaingoldfish.restclient.database.repositories.HttpRequestCategoriesDao;
import de.captaingoldfish.restclient.database.repositories.HttpRequestsDao;
import de.captaingoldfish.restclient.database.repositories.HttpResponseDao;
import de.captaingoldfish.restclient.database.repositories.KeystoreDao;
import de.captaingoldfish.restclient.database.repositories.OpenIdClientDao;
import de.captaingoldfish.restclient.database.repositories.OpenIdProviderDao;
Expand All @@ -41,8 +43,9 @@
import de.captaingoldfish.restclient.scim.endpoints.AuthCodeGrantRequestEndpoint;
import de.captaingoldfish.restclient.scim.endpoints.CurrentWorkflowSettingsEndpoint;
import de.captaingoldfish.restclient.scim.endpoints.HttpClientSettingsEndpoint;
import de.captaingoldfish.restclient.scim.endpoints.HttpRequestGroupEndpointDefinition;
import de.captaingoldfish.restclient.scim.endpoints.HttpRequestEndpointDefinition;
import de.captaingoldfish.restclient.scim.endpoints.HttpRequestGroupEndpointDefinition;
import de.captaingoldfish.restclient.scim.endpoints.HttpResponseHistoryEndpointDefinition;
import de.captaingoldfish.restclient.scim.endpoints.JwtBuilderEndpoint;
import de.captaingoldfish.restclient.scim.endpoints.KeystoreEndpoint;
import de.captaingoldfish.restclient.scim.endpoints.OpenIdClientEndpoint;
Expand Down Expand Up @@ -331,6 +334,26 @@ public ResourceType httpRequestResourceType(ResourceEndpoint resourceEndpoint,
{
HttpRequestHandler handler = new HttpRequestHandler(httpRequestCategoriesDao, httpRequestsDao, httpRequestExecutor);
HttpRequestEndpointDefinition endpoint = new HttpRequestEndpointDefinition(handler);
ResourceType resourceType = resourceEndpoint.registerEndpoint(endpoint);
resourceType.getFeatures().setAutoFiltering(true);
resourceType.getFeatures().setAutoSorting(true);
return resourceType;
}

/**
* registers the http-response history resourceType under the endpoint /HttpResponseHistory.
*
* @param resourceEndpoint the resource endpoint that was previously defined
* @return the http-response-history resource type
*/
@Bean
public ResourceType httpResponseHistoryResourceType(ResourceEndpoint resourceEndpoint,
HttpRequestsDao httpRequestsDao,
HttpResponseDao httpResponseDao)
{
HttpResponseHistoryResourceHandler handler = new HttpResponseHistoryResourceHandler(httpRequestsDao,
httpResponseDao);
HttpResponseHistoryEndpointDefinition endpoint = new HttpResponseHistoryEndpointDefinition(handler);
return resourceEndpoint.registerEndpoint(endpoint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
Expand Down Expand Up @@ -97,8 +98,7 @@ public class HttpRequest
/**
* the http response history of this request
*/
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
// @formatter:off
@JoinTable(name = "HTTP_REQUEST_RESPONSE_MAPPING",
joinColumns = @JoinColumn(name = "HTTP_REQUEST_ID", referencedColumnName = "ID"),
Expand Down
Loading