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; }