Search in sources :

Example 1 with INoarkGeneralEntity

use of nikita.common.model.noark5.v4.interfaces.entities.INoarkGeneralEntity in project nikita-noark5-core by HiOA-ABI.

the class FondsIT method test_2_createFonds.

@Test
public void test_2_createFonds() throws JsonProcessingException {
    assertTrue(checkLoggedIn());
    assertNotNull(headers);
    assertNotNull(headers.get("Authorization"));
    Fonds fonds = new Fonds();
    fonds.setDescription("description");
    fonds.setTitle("title");
    String serializedFonds = mapper.writeValueAsString(fonds);
    HttpEntity<String> request = new HttpEntity<>(serializedFonds, headers);
    ResponseEntity<HateoasNoarkObject> responseEntity = restTemplate.exchange("/hateoas-api/arkivstruktur/ny-arkiv", HttpMethod.POST, request, HateoasNoarkObject.class);
    assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
    HateoasNoarkObject result = responseEntity.getBody();
    ArrayList<INikitaEntity> entities = (ArrayList<INikitaEntity>) result.getList();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);
    INoarkGeneralEntity returnedFonds = (INoarkGeneralEntity) entities.get(0);
    assertEquals("description", returnedFonds.getDescription());
    assertEquals("title", returnedFonds.getTitle());
}
Also used : INoarkGeneralEntity(nikita.common.model.noark5.v4.interfaces.entities.INoarkGeneralEntity) HateoasNoarkObject(nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject) INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) ArrayList(java.util.ArrayList) Fonds(nikita.common.model.noark5.v4.Fonds) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with INoarkGeneralEntity

use of nikita.common.model.noark5.v4.interfaces.entities.INoarkGeneralEntity in project nikita-noark5-core by HiOA-ABI.

the class NoarkImportService method checkAndSetDefaultValues.

/**
     *
     * Check a Noark entity (fonds, series, file, etc) for valid properties and set any values that have not been set
     * that should be set with default values.
     *
     * @param entity
     * @throws Exception
     */
public void checkAndSetDefaultValues(INoarkGeneralEntity entity) throws Exception {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    // Not all Noark objects, i.e DocumentDescription and DocumentObject have a documentMedium property
    if (entity instanceof IDocumentMedium) {
        if (!NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(((IDocumentMedium) entity))) {
            logger.error("Document medium not a valid document medium. Assigned value is " + ((IDocumentMedium) entity).getDocumentMedium());
        // An exception will be thrown  by checkDocumentMediumValid if not valid
        //TODO: Look at the logic here, as a change checkDocumentMediumValid kinda makes
        // the if redundant
        }
    }
    // uniqueness via systemId
    if (entity.getSystemId() == null) {
        entity.setSystemId(UUID.randomUUID().toString());
    } else if (entity.getSystemId().length() != Constants.UUIDLength) {
        String randomUUID = UUID.randomUUID().toString();
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a valid UUID. Original value [" + entity.getSystemId() + entity.toString() + "] is being changed and assigned with [" + randomUUID + "]");
        entity.setSystemId(randomUUID);
    }
    if (entity.getCreatedDate() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdDate value. createdDate is being set to [" + new Date().toString() + "]");
        entity.setCreatedDate(new Date());
    }
    if (entity.getCreatedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setCreatedBy(username);
    }
    if (entity.getOwnedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setOwnedBy(username);
    }
    entity.setDeleted(false);
}
Also used : IDocumentMedium(nikita.model.noark5.v4.interfaces.IDocumentMedium) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Fonds (nikita.common.model.noark5.v4.Fonds)1 HateoasNoarkObject (nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject)1 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)1 INoarkGeneralEntity (nikita.common.model.noark5.v4.interfaces.entities.INoarkGeneralEntity)1 IDocumentMedium (nikita.model.noark5.v4.interfaces.IDocumentMedium)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1