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());
}
}
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 });
}
}
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 });
}
}
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());
}
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;
}
Aggregations