Search in sources :

Example 21 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class IdmIdentityControllerRestTest method testPatchProfile.

@Test
public void testPatchProfile() throws UnsupportedEncodingException, IOException, Exception {
    IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
    // 
    // create + patch profile
    String response = getMockMvc().perform(MockMvcRequestBuilders.patch(getDetailUrl(owner.getId()) + "/profile").with(authentication(getAdminAuthentication())).content(// PATCH => lookout, mappar cannot be used (maps even null attrs).
    "{ \"preferredLanguage\": \"en\" }").contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    IdmProfileDto createdProfile = (IdmProfileDto) getMapper().readValue(response, IdmProfileDto.class);
    Assert.assertEquals(owner.getId(), createdProfile.getIdentity());
    Assert.assertEquals("en", createdProfile.getPreferredLanguage());
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 22 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmProfileService method findOrCreateByIdentity.

@Override
@Transactional
public IdmProfileDto findOrCreateByIdentity(Serializable identityIdentifier, BasePermission... permission) {
    Assert.notNull(identityIdentifier, "Identity identifier is required.");
    IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, identityIdentifier);
    if (identity == null) {
        return null;
    }
    // 
    IdmProfileDto profile = this.findOneByIdentity(identity, permission);
    // 
    if (profile != null) {
        return profile;
    }
    // TODO: two profiles can be created in multi thread access (lock by identity before the get)
    profile = new IdmProfileDto();
    profile.setIdentity(identity.getId());
    // 
    return save(profile, permission);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmProfileService method findOneByIdentity.

private IdmProfileDto findOneByIdentity(IdmIdentityDto identity, BasePermission... permission) {
    Assert.notNull(identity, "Identity is required.");
    // 
    IdmProfileFilter filter = new IdmProfileFilter();
    filter.setIdentityId(identity.getId());
    List<IdmProfileDto> profiles = find(filter, null, permission).getContent();
    // 
    return profiles.isEmpty() ? null : profiles.get(0);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmProfileFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter)

Example 24 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class ProfileDeleteProcessor method process.

@Override
public EventResult<IdmProfileDto> process(EntityEvent<IdmProfileDto> event) {
    IdmProfileDto profile = event.getContent();
    Assert.notNull(profile.getId(), "Profile id is required!");
    // 
    // remove image attachment for this identity
    attachmentManager.deleteAttachments(profile);
    // 
    service.deleteInternal(profile);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 25 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class ProfileSaveProcessor method process.

@Override
public EventResult<IdmProfileDto> process(EntityEvent<IdmProfileDto> event) {
    IdmProfileDto profile = event.getContent();
    profile = service.saveInternal(profile);
    event.setContent(profile);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Aggregations

IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 Test (org.junit.Test)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)6 ApiOperation (io.swagger.annotations.ApiOperation)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IdmProfileFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter)5 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Transactional (org.springframework.transaction.annotation.Transactional)4 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3