Search in sources :

Example 1 with RFocusPhoto

use of com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto in project midpoint by Evolveum.

the class ObjectDeltaUpdaterTest method test300DeletePhoto.

@Test
public void test300DeletePhoto() throws Exception {
    OperationResult result = new OperationResult("test300DeletePhoto");
    ObjectDelta<UserType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid);
    delta.addModificationDeleteProperty(UserType.F_JPEG_PHOTO, new byte[] { 4, 5, 6 });
    TestStatementInspector.start();
    repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);
    TestStatementInspector.dump();
    if (isUsingH2()) {
        AssertJUnit.assertEquals(5, TestStatementInspector.getQueryCount());
    }
    logger.info("test300DeletePhoto check");
    try (Session session = factory.openSession()) {
        RUser u = session.get(RUser.class, userOid);
        Set<RFocusPhoto> p = u.getJpegPhoto();
        AssertJUnit.assertEquals(0, p.size());
    }
}
Also used : RUser(com.evolveum.midpoint.repo.sql.data.common.RUser) RFocusPhoto(com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 2 with RFocusPhoto

use of com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto in project midpoint by Evolveum.

the class ObjectDeltaUpdaterTest method test290ReplacePhoto.

@Test
public void test290ReplacePhoto() throws Exception {
    OperationResult result = new OperationResult("test290ReplacePhoto");
    ObjectDelta<UserType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid);
    delta.addModificationReplaceProperty(UserType.F_JPEG_PHOTO, new byte[] { 4, 5, 6 });
    TestStatementInspector.start();
    repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);
    TestStatementInspector.dump();
    if (isUsingH2()) {
        AssertJUnit.assertEquals(6, TestStatementInspector.getQueryCount());
    }
    logger.info("test290ReplacePhoto check");
    try (Session session = factory.openSession()) {
        RUser u = session.get(RUser.class, userOid);
        Set<RFocusPhoto> p = u.getJpegPhoto();
        AssertJUnit.assertEquals(1, p.size());
        RFocusPhoto photo = p.iterator().next();
        Assert.assertEquals(photo.getPhoto(), new byte[] { 4, 5, 6 });
    }
}
Also used : RUser(com.evolveum.midpoint.repo.sql.data.common.RUser) RFocusPhoto(com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 3 with RFocusPhoto

use of com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto in project midpoint by Evolveum.

the class ObjectDeltaUpdaterTest method test280AddPhoto.

// More photo-related tests should go to UserPhotoTest
@Test
public void test280AddPhoto() throws Exception {
    OperationResult result = new OperationResult("test280AddPhoto");
    ObjectDelta<UserType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid);
    delta.addModificationAddProperty(UserType.F_JPEG_PHOTO, new byte[] { 1, 2, 3 });
    TestStatementInspector.start();
    repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);
    TestStatementInspector.dump();
    if (isUsingH2()) {
        AssertJUnit.assertEquals(6, TestStatementInspector.getQueryCount());
    }
    logger.info("test280AddPhoto check");
    try (Session session = factory.openSession()) {
        RUser u = session.get(RUser.class, userOid);
        Set<RFocusPhoto> p = u.getJpegPhoto();
        AssertJUnit.assertEquals(1, p.size());
        RFocusPhoto photo = p.iterator().next();
        Assert.assertEquals(photo.getPhoto(), new byte[] { 1, 2, 3 });
    }
}
Also used : RUser(com.evolveum.midpoint.repo.sql.data.common.RUser) RFocusPhoto(com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 4 with RFocusPhoto

use of com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto in project midpoint by Evolveum.

the class PhotoUpdate method handlePropertyDelta.

public void handlePropertyDelta() throws SchemaException {
    if (!(object instanceof RFocus)) {
        throw new SystemException("Bean is not instance of " + RFocus.class + ", shouldn't happen");
    }
    RFocus focus = (RFocus) object;
    Set<RFocusPhoto> photos = focus.getJpegPhoto();
    if (isDelete()) {
        photos.clear();
        return;
    }
    MapperContext context = new MapperContext();
    context.setRepositoryContext(beans.createRepositoryContext());
    context.setDelta(delta);
    context.setOwner(object);
    PrismValue value = delta.getAnyValue();
    RFocusPhoto photo = beans.prismEntityMapper.map(value.getRealValue(), RFocusPhoto.class, context);
    if (delta.isAdd()) {
        if (!photos.isEmpty()) {
            throw new SchemaException("Object '" + focus.getOid() + "' already contains photo");
        }
        photo.setTransient(true);
        photos.add(photo);
        return;
    }
    if (photos.isEmpty()) {
        photo.setTransient(true);
        photos.add(photo);
        return;
    }
    RFocusPhoto oldPhoto = photos.iterator().next();
    oldPhoto.setPhoto(photo.getPhoto());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) MapperContext(com.evolveum.midpoint.repo.sql.helpers.modify.MapperContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) RFocusPhoto(com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto) RFocus(com.evolveum.midpoint.repo.sql.data.common.RFocus) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 5 with RFocusPhoto

use of com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto in project midpoint by Evolveum.

the class RFocusPhotoMapper method map.

@Override
public RFocusPhoto map(byte[] input, MapperContext context) {
    RFocusPhoto photo = new RFocusPhoto();
    photo.setOwner((RFocus) context.getOwner());
    photo.setPhoto(input);
    return photo;
}
Also used : RFocusPhoto(com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto)

Aggregations

RFocusPhoto (com.evolveum.midpoint.repo.sql.data.common.RFocusPhoto)5 RUser (com.evolveum.midpoint.repo.sql.data.common.RUser)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Session (org.hibernate.Session)3 Test (org.testng.annotations.Test)3 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 RFocus (com.evolveum.midpoint.repo.sql.data.common.RFocus)1 MapperContext (com.evolveum.midpoint.repo.sql.helpers.modify.MapperContext)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1