protected void persistNode(final Object copy, final MultiTenantCopyContext context) { if (!genericEntityService.sessionContains(copy) && !genericEntityService.idAssigned(copy)) { final Object original = genericEntityService.readGenericEntity(copy.getClass().getName(), context.removeOriginalIdentifier(copy)); extensionManager.getProxy().transformCopy(context, original, copy); extensionManager.getProxy().prepareForSave(context, original, copy); IdentityExecutionUtils.runOperationByIdentifier(new IdentityOperation<Void, RuntimeException>() { @Override public Void execute() { genericEntityService.persist(copy); extensionManager.getProxy().postSave(context, original, copy); return null; } }, context.getToSite(), context.getToSite(), context.getToCatalog()); context.storeEquivalentMapping(original.getClass().getName(), context.getIdentifier(original), context.getIdentifier(copy)); } }
protected <G> CreateResponse<G> handleStandardEntity(Object instance, BroadleafRequestContext context, Class<?> instanceClass) throws CloneNotSupportedException { CreateResponse<G> createResponse; Long originalId = getIdentifier(instance); Object previousClone = getPreviousClone(instanceClass, originalId); G response; boolean alreadyPopulate; if (previousClone != null) { response = (G) previousClone; alreadyPopulate = true; } else { boolean shouldClone = checkCloneStatus(instance); if (!shouldClone) { response = (G) instance; alreadyPopulate = true; } else { alreadyPopulate = false; response = performCopy(instance, instanceClass, originalId); } } createResponse = new CreateResponse<G>(response, alreadyPopulate); return createResponse; }
@Override public <G extends Translation> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this); if (createResponse.isAlreadyPopulated()) { return createResponse; } Translation cloned = createResponse.getClone(); //this assumes that TranslationImpl copying occurs last after all other entity copying Object referenceClone; try { referenceClone = context.getPreviousClone(Class.forName(getEntityType().getType()), Long.parseLong(entityId)); } catch (ClassNotFoundException e) { throw ExceptionHelper.refineException(e); } String convertedId = entityId; if (referenceClone != null) { convertedId = String.valueOf(context.getIdentifier(referenceClone)); } cloned.setEntityId(convertedId); cloned.setFieldName(fieldName); cloned.setLocaleCode(localeCode); cloned.setTranslatedValue(translatedValue); cloned.setEntityType(getEntityType()); return createResponse; }