Skip to content

Commit

Permalink
cleanup and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jan 26, 2018
1 parent 36a094c commit 48dedf5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
Expand Up @@ -29,9 +29,11 @@
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.EntityRegistry;
import com.evolveum.midpoint.repo.sql.helpers.modify.MapperContext;
import com.evolveum.midpoint.repo.sql.helpers.modify.PrismEntityMapper;
import com.evolveum.midpoint.repo.sql.util.EntityState;
import com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
Expand All @@ -50,7 +52,6 @@

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 All @@ -70,7 +71,7 @@ public class ObjectDeltaUpdater {
private static final Trace LOGGER = TraceManager.getTrace(ObjectDeltaUpdater.class);

@Autowired
private EntityModificationRegistry entityModificationRegistry;
private EntityRegistry entityModificationRegistry;
@Autowired
private PrismContext prismContext;
@Autowired
Expand All @@ -79,20 +80,20 @@ public class ObjectDeltaUpdater {
/**
* modify
*/
public <T extends ObjectType> RObject<T> buildUpdatedObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications,
PrismObject<T> prismObject, Session session) {
public <T extends ObjectType> RObject<T> modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications,
PrismObject<T> prismObject, Session session) throws SchemaException {

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

// 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
// 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/ownerType for containers/references/result and others

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

// todo validate lookup tables and certification campaigns
// validate lookup tables and certification campaigns

// todo mark newly added containers/references as transient

Expand Down Expand Up @@ -153,13 +154,39 @@ public <T extends ObjectType> RObject<T> buildUpdatedObject(Class<T> type, Strin
String strVersion = prismObject.getVersion();
int version = StringUtils.isNotEmpty(strVersion) && strVersion.matches("[0-9]*") ? Integer.parseInt(strVersion) + 1 : 1;
object.setVersion(version);

// apply modifications, ids' for new containers already filled in delta values
ItemDelta.applyTo(modifications, prismObject);

handleObjectTextInfoChanges(type, modifications, object);

// generate ids for containers that weren't handled in previous step (not processed by repository)
PrismIdentifierGenerator generator = new PrismIdentifierGenerator();
generator.generate(prismObject, PrismIdentifierGenerator.Operation.MODIFY);

// full object column will be updated later

LOGGER.debug("Entity changes applied");

return object;
}

private <T extends ObjectType> boolean isObjectTextInfoRecomputationNeeded(Class<T> type, Collection<? extends ItemDelta> modifications) {
// todo implement
return false;
}

private <T extends ObjectType> void handleObjectTextInfoChanges(Class<T> type, Collection<? extends ItemDelta> modifications,
RObject object) {
// update object text info if necessary
if (!isObjectTextInfoRecomputationNeeded(type, modifications)) {
return;
}

// todo implement
//ItemDelta.findItemDeltasSubPath()
}

private boolean isObjectExtensionDelta(ItemPath path) {
return path.startsWithName(ObjectType.F_EXTENSION);
}
Expand Down
Expand Up @@ -423,13 +423,7 @@ public <T extends ObjectType> void modifyObjectAttempt(Class<T> type, String oid
originalObject = prismObject.clone();
}

RObject rObject = objectDeltaUpdater.buildUpdatedObject(type, oid, modifications, prismObject, session);
// apply modifications, ids' for new containers already filled in delta values
ItemDelta.applyTo(modifications, prismObject);

// generate ids for containers that weren't handled in previous step (not processed by repository)
PrismIdentifierGenerator generator = new PrismIdentifierGenerator();
generator.generate(prismObject, PrismIdentifierGenerator.Operation.MODIFY);
RObject rObject = objectDeltaUpdater.modifyObject(type, oid, modifications, prismObject, session);

LOGGER.trace("OBJECT after:\n{}", prismObject.debugDumpLazily());
// Continuing the photo treatment: should we remove the (now obsolete) focus photo?
Expand Down
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

package com.evolveum.midpoint.repo.sql.helpers;
package com.evolveum.midpoint.repo.sql.helpers.modify;

import com.evolveum.midpoint.repo.sql.data.common.RObject;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.helpers.modify.Ignore;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbName;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbPath;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbType;
Expand All @@ -39,15 +38,12 @@
import java.util.Set;

/**
* // todo documentation, cleanup, probably rename class & methods
*
* @author Viliam Repan (lazyman)
*/

@Service
public class EntityModificationRegistry {
public class EntityRegistry {

private static final Trace LOGGER = TraceManager.getTrace(EntityModificationRegistry.class);
private static final Trace LOGGER = TraceManager.getTrace(EntityRegistry.class);

@Autowired
private SessionFactory sessionFactory;
Expand All @@ -58,15 +54,12 @@ public class EntityModificationRegistry {

private Map<ManagedType, Map<String, Attribute>> attributeNameOverrides = new HashMap<>();


// todo handle RObjectTextInfo
// todo handle RAssignmentExtension

@PostConstruct
public void init() {
// todo implement
LOGGER.debug("Starting initialization");

metamodel = sessionFactory.getMetamodel();

for (EntityType entity : metamodel.getEntities()) {
Class javaType = entity.getJavaType();
Ignore ignore = (Ignore) javaType.getAnnotation(Ignore.class);
Expand Down Expand Up @@ -114,12 +107,12 @@ public void init() {
LOGGER.debug("Initialization finished");
}

public ManagedType getJaxbMapping(Class type) {
return jaxbMappings.get(type);
public ManagedType getJaxbMapping(Class jaxbType) {
return jaxbMappings.get(jaxbType);
}

public ManagedType getMapping(Class type) {
return metamodel.managedType(type);
public ManagedType getMapping(Class entityType) {
return metamodel.managedType(entityType);
}

public Attribute findAttribute(ManagedType type, String name) {
Expand Down

0 comments on commit 48dedf5

Please sign in to comment.