Search in sources :

Example 1 with KbCredentialsDataAttributes

use of org.folio.rest.jaxrs.model.KbCredentialsDataAttributes in project mod-kb-ebsco-java by folio-org.

the class KbCredentialsPatchRequestConverter method convert.

@Override
public KbCredentials convert(@NonNull KbCredentialsPatchRequest source) {
    KbCredentialsPatchRequestData data = source.getData();
    KbCredentialsPatchRequestDataAttributes attributes = data.getAttributes();
    return new KbCredentials().withId(data.getId()).withAttributes(new KbCredentialsDataAttributes().withApiKey(attributes.getApiKey()).withCustomerId(attributes.getCustomerId()).withName(attributes.getName()).withUrl(attributes.getUrl()));
}
Also used : KbCredentialsPatchRequestData(org.folio.rest.jaxrs.model.KbCredentialsPatchRequestData) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes) KbCredentialsPatchRequestDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsPatchRequestDataAttributes)

Example 2 with KbCredentialsDataAttributes

use of org.folio.rest.jaxrs.model.KbCredentialsDataAttributes in project mod-kb-ebsco-java by folio-org.

the class KbCredentialsServiceImpl method updatePartially.

@Override
public CompletableFuture<Void> updatePartially(String id, KbCredentialsPatchRequest entity, Map<String, String> okapiHeaders) {
    KbCredentials patchRequestData = convertPatchToCredentials(entity);
    patchBodyValidator.validate(patchRequestData);
    KbCredentialsDataAttributes attributes = patchRequestData.getAttributes();
    return prepareAndSave(fetchDbKbCredentials(id, okapiHeaders), (dbCredentials, userInfo) -> preparePartialUpdateEntity(dbCredentials, attributes, userInfo), okapiHeaders).thenApply(dbKbCredentials -> null);
}
Also used : KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) DbKbCredentials(org.folio.repository.kbcredentials.DbKbCredentials) KbCredentialsPutBodyValidator(org.folio.rest.validator.kbcredentials.KbCredentialsPutBodyValidator) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) BiFunction(java.util.function.BiFunction) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationInvalidException(org.folio.holdingsiq.service.exception.ConfigurationInvalidException) CompletableFuture(java.util.concurrent.CompletableFuture) KbCredentialsCollection(org.folio.rest.jaxrs.model.KbCredentialsCollection) Function(java.util.function.Function) Context(io.vertx.core.Context) ConfigurationService(org.folio.holdingsiq.service.ConfigurationService) KbCredentialsKey(org.folio.rest.jaxrs.model.KbCredentialsKey) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) RowSetUtils.fromUUID(org.folio.db.RowSetUtils.fromUUID) ConversionService(org.springframework.core.convert.ConversionService) KbCredentialsPatchBodyValidator(org.folio.rest.validator.kbcredentials.KbCredentialsPatchBodyValidator) KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) OkapiData(org.folio.holdingsiq.model.OkapiData) UserInfo(org.folio.util.UserInfo) Collection(java.util.Collection) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) TenantTool.tenantId(org.folio.rest.tools.utils.TenantTool.tenantId) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) HoldingsService(org.folio.service.holdings.HoldingsService) StringUtils.defaultIfBlank(org.apache.commons.lang3.StringUtils.defaultIfBlank) OffsetDateTime(java.time.OffsetDateTime) KbCredentialsPatchRequest(org.folio.rest.jaxrs.model.KbCredentialsPatchRequest) ServiceExceptions(org.folio.service.exc.ServiceExceptions) KbCredentialsPostBodyValidator(org.folio.rest.validator.kbcredentials.KbCredentialsPostBodyValidator) Optional(java.util.Optional) Configuration(org.folio.holdingsiq.model.Configuration) TokenUtils.fetchUserInfo(org.folio.util.TokenUtils.fetchUserInfo) KbCredentialsRepository(org.folio.repository.kbcredentials.KbCredentialsRepository) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) DbKbCredentials(org.folio.repository.kbcredentials.DbKbCredentials) KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes)

Example 3 with KbCredentialsDataAttributes

use of org.folio.rest.jaxrs.model.KbCredentialsDataAttributes in project mod-kb-ebsco-java by folio-org.

the class KbCredentialsPatchBodyValidator method validate.

public void validate(KbCredentials patchRequest) {
    KbCredentialsDataAttributes attributes = patchRequest.getAttributes();
    ValidatorUtil.checkIsNotAllBlank("attributes", attributes.getApiKey(), attributes.getCustomerId(), attributes.getName(), attributes.getUrl());
    if (attributes.getName() != null) {
        validateName(attributes);
    }
    if (attributes.getApiKey() != null) {
        validateApiKey(attributes);
    }
    if (attributes.getCustomerId() != null) {
        validateCustomerId(attributes);
    }
    if (attributes.getUrl() != null) {
        validateUrl(attributes);
    }
}
Also used : KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes)

Example 4 with KbCredentialsDataAttributes

use of org.folio.rest.jaxrs.model.KbCredentialsDataAttributes in project mod-kb-ebsco-java by folio-org.

the class KbCredentialsBodyAttributesValidatorTest method shouldThrowExceptionWhenNullUrl.

@Test
public void shouldThrowExceptionWhenNullUrl() {
    expectedEx.expect(InputValidationException.class);
    expectedEx.expectMessage("Invalid url");
    KbCredentialsDataAttributes attributes = new KbCredentialsDataAttributes().withName("name").withApiKey("key").withCustomerId("custId");
    validator.validateAttributes(attributes);
}
Also used : KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes) Test(org.junit.Test)

Example 5 with KbCredentialsDataAttributes

use of org.folio.rest.jaxrs.model.KbCredentialsDataAttributes in project mod-kb-ebsco-java by folio-org.

the class KbCredentialsBodyAttributesValidatorTest method shouldThrowExceptionWhenEmptyName.

@Test
public void shouldThrowExceptionWhenEmptyName() {
    expectedEx.expect(InputValidationException.class);
    expectedEx.expectMessage("Invalid name");
    KbCredentialsDataAttributes attributes = new KbCredentialsDataAttributes().withName("").withApiKey("key").withCustomerId("custId").withUrl("http://example.com");
    validator.validateAttributes(attributes);
}
Also used : KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes) Test(org.junit.Test)

Aggregations

KbCredentialsDataAttributes (org.folio.rest.jaxrs.model.KbCredentialsDataAttributes)14 Test (org.junit.Test)10 KbCredentials (org.folio.rest.jaxrs.model.KbCredentials)3 Context (io.vertx.core.Context)2 OffsetDateTime (java.time.OffsetDateTime)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2 StringUtils.defaultIfBlank (org.apache.commons.lang3.StringUtils.defaultIfBlank)2 RowSetUtils.fromUUID (org.folio.db.RowSetUtils.fromUUID)2 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)2 Configuration (org.folio.holdingsiq.model.Configuration)2 OkapiData (org.folio.holdingsiq.model.OkapiData)2 ConfigurationService (org.folio.holdingsiq.service.ConfigurationService)2 ConfigurationInvalidException (org.folio.holdingsiq.service.exception.ConfigurationInvalidException)2