Skip to content

Commit

Permalink
changed modify operation, prepared for correct id generator, test sta…
Browse files Browse the repository at this point in the history
…rt failing
  • Loading branch information
1azyman committed Jan 24, 2018
1 parent ec3d94c commit aee25bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
Expand Up @@ -57,8 +57,7 @@ public class ObjectDeltaUpdaterTest extends BaseSQLRepoTest {

private static final String FILE_USER = "user.xml";

// @Autowired
// private EntityModificationRegistry entityModificationRegistry;
// todo don't store non indexed extension attributes

@Test
public <T extends ObjectType> void addLinkRef() throws Exception {
Expand Down
Expand Up @@ -61,4 +61,14 @@ public static <T extends RObject> RObjectType getType(Class<T> clazz) {

throw new IllegalArgumentException("Couldn't find type for class '" + clazz + "'.");
}

public static <T extends ObjectType> RObjectType getByJaxbType(Class<T> clazz) {
for (RObjectType type : RObjectType.values()) {
if (type.getJaxbClass().equals(clazz)) {
return type;
}
}

throw new IllegalArgumentException("Couldn't find type for class '" + clazz + "'.");
}
}
Expand Up @@ -28,6 +28,7 @@
import com.evolveum.midpoint.repo.sql.data.common.any.*;
import com.evolveum.midpoint.repo.sql.data.common.container.Container;
import com.evolveum.midpoint.repo.sql.data.common.container.RAssignment;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.data.common.type.RAssignmentExtensionType;
import com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType;
import com.evolveum.midpoint.repo.sql.helpers.modify.PrismEntityMapper;
Expand All @@ -41,12 +42,14 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.ManagedType;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
Expand Down Expand Up @@ -75,30 +78,25 @@ public class ObjectDeltaUpdater {
/**
* modify
*/
public <T extends ObjectType> RObject<T> update(Class<T> type, String oid, Collection<? extends ItemDelta> modifications,
RObject<T> objectToMerge, Session session, OperationResult result) {
public <T extends ObjectType> RObject<T> buildUpdatedObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications,
PrismObject<T> prismObject, Session session) {

LOGGER.debug("Starting to build entity changes based on delta via reference");

if (1 == 1) {
return merge(objectToMerge, session);
}
// todo normalize reference.relation qnames like it's done here ObjectTypeUtil.normalizeAllRelations(prismObject);

// todo how to generate identifiers correctly now? to repo entities and to full xml, ids in full XML are generated on different place than we later create new containers...how to match them

// todo set proper owner/ownerOid for containers/references
// todo set proper owner/ownerOid/ownerType for containers/references/result and others

// todo implement transformation from prism to entity (PrismEntityMapper)

// todo validate lookup tables and certification campaigns

// todo mark newly added containers/references as transient

// todo don't store non indexed extension attributes

RObject object = session.byId(objectToMerge.getClass()).getReference(oid);
object.setVersion(objectToMerge.getVersion());
object.setFullObject(objectToMerge.getFullObject());
Class<? extends RObject> objectClass = RObjectType.getByJaxbType(type).getClazz();
RObject<T> object = session.byId(objectClass).getReference(oid);

ManagedType mainEntityType = entityModificationRegistry.getJaxbMapping(type);

Expand Down Expand Up @@ -150,13 +148,14 @@ public <T extends ObjectType> RObject<T> update(Class<T> type, String oid, Colle
}
}

LOGGER.debug("Saving object");
// update version and full xml object
String strVersion = prismObject.getVersion();
int version = StringUtils.isNotEmpty(strVersion) && strVersion.matches("[0-9]*") ? Integer.parseInt(strVersion) + 1 : 1;
object.setVersion(version);

session.save(object);
LOGGER.debug("Entity changes applied");

LOGGER.debug("Object saved");

return objectToMerge;
return object;
}

private boolean isObjectExtensionDelta(ItemPath path) {
Expand Down Expand Up @@ -190,8 +189,6 @@ private void handleAssignmentExtensionDelta(RAssignment assignment, ItemDelta de
}

processAnyExtensionDeltaValues(delta, null, null, extension, RAssignmentExtensionType.EXTENSION);

// todo if extension is empty, null it probably
}

private void processAnyExtensionDeltaValues(Collection<PrismValue> values,
Expand Down
Expand Up @@ -253,7 +253,7 @@ private <T extends ObjectType> List<ReferenceDelta> createAddParentRefDelta(Pris
}

public <T extends ObjectType> void updateFullObject(RObject object, PrismObject<T> savedObject)
throws DtoTranslationException, SchemaException {
throws SchemaException {
LOGGER.debug("Updating full object xml column start.");
savedObject.setVersion(Integer.toString(object.getVersion()));

Expand Down Expand Up @@ -422,22 +422,19 @@ public <T extends ObjectType> void modifyObjectAttempt(Class<T> type, String oid
if (closureManager.isEnabled()) {
originalObject = prismObject.clone();
}

RObject rObject = objectDeltaUpdater.buildUpdatedObject(type, oid, modifications, prismObject, session);

ItemDelta.applyTo(modifications, prismObject);
LOGGER.trace("OBJECT after:\n{}", prismObject.debugDumpLazily());
// Continuing the photo treatment: should we remove the (now obsolete) focus photo?
// We have to test prismObject at this place, because updateFullObject (below) removes photo property from the prismObject.
boolean shouldPhotoBeRemoved = containsFocusPhotoModification && ((FocusType) prismObject.asObjectable()).getJpegPhoto() == null;

// merge and update object
// todo remove this createDataObjectFromJAXB [lazyman], it's unnecessary when we're handling deltas manually
LOGGER.trace("Translating JAXB to data type.");
ObjectTypeUtil.normalizeAllRelations(prismObject);
RObject rObject = createDataObjectFromJAXB(prismObject, PrismIdentifierGenerator.Operation.MODIFY);
rObject.setVersion(rObject.getVersion() + 1);

updateFullObject(rObject, prismObject);
LOGGER.trace("Starting merge.");
objectDeltaUpdater.update(type, oid, modifications, rObject, session, result);
LOGGER.trace("Starting save.");

session.save(rObject);

if (closureManager.isEnabled()) {
closureManager.updateOrgClosure(originalObject, modifications, session, oid, type, OrgClosureManager.Operation.MODIFY, closureContext);
Expand Down

0 comments on commit aee25bc

Please sign in to comment.