Search in sources :

Example 11 with User

use of nikita.common.model.noark5.v4.admin.User in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryHateoasController method getCorrespondencePartUnitTemplate.

// Create a suggested CorrespondencePartUnit (like a template) object with default values (nothing persisted)
// GET [contextPath][api]/casehandling/journalpost/{systemId}/ny-korrespondansepartenhet
@ApiOperation(value = "Suggests the contents of a new CorrespondencePart object", notes = "Returns a pre-filled CorrespondencePart object" + " with values relevant for the logged-in user", response = CorrespondencePartUnitHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "CorrespondencePart " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CorrespondencePartUnitHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.GET, value = { SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CORRESPONDENCE_PART_UNIT })
public ResponseEntity<CorrespondencePartUnitHateoas> getCorrespondencePartUnitTemplate(HttpServletRequest request) throws NikitaException {
    CorrespondencePartUnit suggestedCorrespondencePart = new CorrespondencePartUnit();
    CorrespondencePartType correspondencePartType = correspondencePartTypeService.findByCode(CORRESPONDENCE_PART_CODE_EA);
    if (correspondencePartType == null) {
        throw new NikitaException("Internal error, metadata missing. [" + CORRESPONDENCE_PART_CODE_EA + "] returns no value");
    }
    suggestedCorrespondencePart.setCorrespondencePartType(correspondencePartType);
    PostalAddress postalAddress = new PostalAddress();
    postalAddress.setAddressType(POSTAL_ADDRESS);
    postalAddress.setAddressLine1("ADRL1: 744 Evergreen Terrace");
    postalAddress.setAddressLine2("ADRL2: 744 Evergreen Terrace");
    postalAddress.setAddressLine3("ADRL3: 744 Evergreen Terrace");
    postalAddress.setCountryCode("US");
    postalAddress.setPostalNumber(new PostalNumber("12345"));
    postalAddress.setPostalTown("Springfield");
    suggestedCorrespondencePart.setPostalAddress(postalAddress);
    BusinessAddress businessAddress = new BusinessAddress();
    businessAddress.setAddressType(BUSINESS_ADDRESS);
    businessAddress.setAddressLine1("ADRL1: 745 Evergreen Terrace");
    businessAddress.setAddressLine2("ADRL2: 745 Evergreen Terrace");
    businessAddress.setAddressLine3("ADRL3: 745 Evergreen Terrace");
    businessAddress.setCountryCode("US");
    businessAddress.setPostalNumber(new PostalNumber("12345"));
    businessAddress.setPostalTown("Springfield");
    suggestedCorrespondencePart.setBusinessAddress(businessAddress);
    suggestedCorrespondencePart.setContactPerson("Frank Contact Person Grimes");
    ContactInformation contactInformation = new ContactInformation();
    contactInformation.setEmailAddress("nikita@example.com");
    contactInformation.setMobileTelephoneNumber("123456789");
    contactInformation.setTelephoneNumber("987654321");
    suggestedCorrespondencePart.setContactInformation(contactInformation);
    suggestedCorrespondencePart.setName("Frank Grimes");
    CorrespondencePartUnitHateoas correspondencePartHateoas = new CorrespondencePartUnitHateoas(suggestedCorrespondencePart);
    correspondencePartHateoasHandler.addLinksOnTemplate(correspondencePartHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(correspondencePartHateoas);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) CorrespondencePartType(nikita.model.noark5.v4.metadata.CorrespondencePartType) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with User

use of nikita.common.model.noark5.v4.admin.User in project nikita-noark5-core by HiOA-ABI.

the class ApplicationTests method createFondsObject.

/**
     * Test ability to create a correct fonds object with required administration. Expected return value
     * is 200 OK and the original Fonds object
     */
@Test
@WithMockUser(username = "admin", roles = { "USER", "ADMIN" })
public void createFondsObject() throws Exception {
    String fondsTitle = "Test fonds title   ";
    String fondsDescription = "Test fonds description. This fonds should be automatically deleted after tests are undertaken";
    Fonds fonds = new Fonds();
    fonds.setTitle(fondsTitle);
    fonds.setDescription(fondsDescription);
    fonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
    mockMvc.perform(post("/" + HATEOAS_API_PATH + "/" + FONDS).contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(fonds))).andExpect(status().isOk());
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with User

use of nikita.common.model.noark5.v4.admin.User in project nikita-noark5-core by HiOA-ABI.

the class ApplicationTests method getFondsObject.

@Test
@WithMockUser(username = "admin", roles = { "USER", "ADMIN" })
public void getFondsObject() throws Exception {
    String fondsTitle = "Test fonds title   ";
    String fondsDescription = "Test fonds description. This fonds should be automatically deleted after tests are undertaken";
    Fonds fonds = new Fonds();
    fonds.setTitle(fondsTitle);
    fonds.setDescription(fondsDescription);
    fonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
    ResultActions result = mockMvc.perform(get("/" + HATEOAS_API_PATH + "/" + FONDS + "/1")).andExpect(status().isOk()).andDo(print()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.title").value(fondsTitle));
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) ResultActions(org.springframework.test.web.servlet.ResultActions) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with User

use of nikita.common.model.noark5.v4.admin.User in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryHateoasController method getCorrespondencePartInternalTemplate.

// Create a suggested CorrespondencePartInternal (like a template) object with default values (nothing persisted)
// GET [contextPath][api]/casehandling/journalpost/{systemId}/ny-korrespondansepartintern
@ApiOperation(value = "Suggests the contents of a new CorrespondencePartInternal object", notes = "Returns a pre-filled CorrespondencePartInternal object" + " with values relevant for the logged-in user", response = CorrespondencePartInternalHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "CorrespondencePart " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CorrespondencePartInternalHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.GET, value = { SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CORRESPONDENCE_PART_INTERNAL })
public ResponseEntity<String> getCorrespondencePartInternalTemplate(HttpServletRequest request) throws NikitaException {
    CorrespondencePartInternal suggestedCorrespondencePart = new CorrespondencePartInternal();
    CorrespondencePartType correspondencePartType = correspondencePartTypeService.findByCode(CORRESPONDENCE_PART_CODE_EA);
    if (correspondencePartType == null) {
        throw new NikitaException("Internal error, metadata missing. [" + CORRESPONDENCE_PART_CODE_EA + "] returns no value");
    }
    suggestedCorrespondencePart.setCorrespondencePartType(correspondencePartType);
    // The reason this is not implemented is that we are missing AdministrativeUnit and multiple users
    CorrespondencePartInternalHateoas correspondencePartHateoas = new CorrespondencePartInternalHateoas(suggestedCorrespondencePart);
    correspondencePartHateoasHandler.addLinksOnTemplate(correspondencePartHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body("");
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) Authorisation(nikita.webapp.security.Authorisation) CorrespondencePartType(nikita.common.model.noark5.v4.metadata.CorrespondencePartType) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)9 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Authorisation (nikita.webapp.security.Authorisation)6 Timed (com.codahale.metrics.annotation.Timed)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 CorrespondencePartType (nikita.common.model.noark5.v4.metadata.CorrespondencePartType)3 NikitaException (nikita.common.util.exceptions.NikitaException)3 Fonds (nikita.model.noark5.v4.Fonds)3 CorrespondencePartType (nikita.model.noark5.v4.metadata.CorrespondencePartType)3 NikitaException (nikita.util.exceptions.NikitaException)3 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 Fonds (nikita.common.model.noark5.v4.Fonds)1 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)1 Series (nikita.common.model.noark5.v4.Series)1 User (nikita.common.model.noark5.v4.admin.User)1 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)1 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)1