Example usage for org.hibernate Hibernate isInitialized

List of usage examples for org.hibernate Hibernate isInitialized

Introduction

In this page you can find the example usage for org.hibernate Hibernate isInitialized.

Prototype

@SuppressWarnings("SimplifiableIfStatement")
public static boolean isInitialized(Object proxy) 

Source Link

Document

Check if the proxy or persistent collection is initialized.

Usage

From source file:net.firejack.platform.core.config.meta.factory.GroupElementFactory.java

License:Apache License

@Override
protected void initDescriptorElementSpecific(GroupElement groupElement, GroupModel group) {
    super.initDescriptorElementSpecific(groupElement, group);
    if (group.getDirectory() != null) {
        if (Hibernate.isInitialized(group.getDirectory())) {
            groupElement.setDirectoryRef(group.getDirectory().getLookup());
            groupElement.setPath(null);/*from   w w  w.j  a v a  2  s .  co  m*/
        }
    } else if (group.getParent() != null && Hibernate.isInitialized(group.getParent())
            && group.getParent().getType() == RegistryNodeType.DIRECTORY) {
        groupElement.setDirectoryRef(group.getParent().getLookup());
    }
}

From source file:net.firejack.platform.core.config.meta.factory.PackageDescriptorConfigElementFactory.java

License:Apache License

/**
 * @param element//w ww  . ja v a 2 s .  c  om
 * @param model
 * @param uidModelStore
 */
public static void initializeConfigElementUID(INamedPackageDescriptorElement element, UIDModel model,
        IUIDStore<? extends UIDModel, Long> uidModelStore) {
    if (model != null && model.getUid() != null) {
        if (Hibernate.isInitialized(model.getUid())) {
            element.setUid(model.getUid().getUid());
        } else {
            UID uid = uidModelStore.uidById(model.getUid().getId());
            element.setUid(uid.getUid());
        }
    }
}

From source file:net.firejack.platform.core.config.meta.factory.ProcessFieldElementFactory.java

License:Apache License

@Override
protected void initDescriptorElementSpecific(ProcessFieldElement fieldElement, ProcessFieldModel processField) {
    super.initDescriptorElementSpecific(fieldElement, processField);

    fieldElement.setDisplayName(processField.getName());
    fieldElement.setFormat(processField.getFormat());
    fieldElement.setGlobal(processField.getGlobal());
    fieldElement.setOrderPosition(processField.getOrderPosition());
    fieldElement.setValueType(processField.getValueType());
    fieldElement.setPath(null);//w  w  w  . ja  v  a2s  . co m

    EntityModel entity = processField.getRegistryNodeType();
    if (Hibernate.isInitialized(entity)) {
        if (Hibernate.isInitialized(entity.getUid())) {
            EntityReference entityReference = new EntityReference();
            entityReference.setEntityUid(entity.getUid().getUid());
            fieldElement.setEntityReference(entityReference);

            if (Hibernate.isInitialized(processField.getField().getUid())) {
                FieldReference fieldReference = new FieldReference();
                fieldReference.setFieldUid(processField.getField().getUid().getUid());
                fieldElement.setFieldReference(fieldReference);
                PackageDescriptorConfigElementFactory.initializeConfigElementUID(fieldElement, processField,
                        processFieldStore);
            } else {
                throw new OpenFlameRuntimeException(
                        "UID of field referenced by Process Field is not initialized.");
            }
        } else {
            throw new OpenFlameRuntimeException("Referenced entity has uninitialized UID property.");
        }
    } else {
        throw new OpenFlameRuntimeException("Referenced entity is not initialized.");
    }
}

From source file:net.firejack.platform.core.config.meta.factory.ReportElementFactory.java

License:Apache License

@Override
protected void initDescriptorElementSpecific(ReportElement reportElement, ReportModel report) {
    super.initDescriptorElementSpecific(reportElement, report);
    List<ReportFieldModel> fields = report.getFields();
    if (Hibernate.isInitialized(fields)) {
        List<ReportField> reportFields = new ArrayList<ReportField>(fields.size());
        for (ReportFieldModel field : fields) {
            ReportField element = new ReportField();
            List<RelationshipModel> relationships = field.getRelationships();
            if (relationships != null) {
                List<Reference> references = new ArrayList<Reference>(reportFields.size());
                for (RelationshipModel relationship : relationships)
                    references.add(new Reference(relationship.getName(), relationship.getPath()));
                element.setRelationships(references);
            }//  ww  w. ja v  a2s.com
            FieldModel fieldModel = field.getField();
            element.setField(fieldModel.getLookup());
            element.setDisplayName(field.getDisplayName());
            element.setVisible(field.getVisible());
            element.setSearchable(field.getSearchable());

            reportFields.add(element);
        }
        reportElement.setFields(reportFields);
    }
    reportElement.setName(report.getName());
    reportElement.setPath(report.getPath());
    reportElement.setDescription(report.getDescription());
}

From source file:net.firejack.platform.core.config.meta.factory.ScheduleElementFactory.java

License:Apache License

@Override
protected void initDescriptorElementSpecific(ScheduleElement scheduleElement, ScheduleModel schedule) {
    super.initDescriptorElementSpecific(scheduleElement, schedule);
    if (Hibernate.isInitialized(schedule.getAction())) {
        scheduleElement.setActionRef(schedule.getAction().getLookup());
        scheduleElement.setPath(null);//from  w  w w .  j a  v  a 2 s  .c o m
    }
    scheduleElement.setName(schedule.getName());
    scheduleElement.setPath(schedule.getPath());
    scheduleElement.setDescription(schedule.getDescription());
    scheduleElement.setCronExpression(schedule.getCronExpression());
    scheduleElement.setEmailFailure(schedule.getEmailFailure());
    scheduleElement.setActive(schedule.getActive());
}

From source file:net.firejack.platform.core.config.meta.factory.WizardElementFactory.java

License:Apache License

@Override
protected void initDescriptorElementSpecific(WizardElement wizardElement, WizardModel wizard) {
    super.initDescriptorElementSpecific(wizardElement, wizard);
    List<WizardFieldModel> fields = wizard.getFields();
    if (fields != null) {
        if (Hibernate.isInitialized(fields)) {
            Map<Long, WizardFormElement> wizardFormElements = new LinkedHashMap<Long, WizardFormElement>();
            for (WizardFieldModel field : fields) {
                WizardFieldModel form = field.getForm();
                if (form != null) {
                    WizardFormElement wizardFormElement = wizardFormElements.get(form.getId());
                    if (wizardFormElement == null) {
                        wizardFormElement = new WizardFormElement();
                        wizardFormElement.setDisplayName(form.getDisplayName());
                        wizardFormElements.put(form.getId(), wizardFormElement);
                    }//from  w  ww  .j  a v a2 s.c  om

                    List<WizardFieldElement> wizardFieldElements = wizardFormElement.getFields();
                    if (wizardFieldElements == null) {
                        wizardFieldElements = new ArrayList<WizardFieldElement>();
                        wizardFormElement.setFields(wizardFieldElements);
                    }
                    WizardFieldElement wizardField = new WizardFieldElement();
                    if (field.getField() != null) {
                        wizardField.setField(field.getField().getLookup());
                    }
                    if (field.getRelationship() != null) {
                        wizardField.setRelationship(field.getRelationship().getLookup());
                    }
                    wizardField.setDisplayName(field.getDisplayName());
                    wizardField.setEditable(field.getEditable());
                    wizardField.setDefaultValue(field.getDefaultValue());
                    wizardFieldElements.add(wizardField);
                }
            }
            wizardElement.setForms(new ArrayList<WizardFormElement>(wizardFormElements.values()));
        }
    }
    wizardElement.setName(wizard.getName());
    wizardElement.setPath(wizard.getPath());
    wizardElement.setDescription(wizard.getDescription());
    RegistryNodeModel main = wizard.getMain();
    if (main == null) {
        logger.error("Main model information is not set for the wizard [name = " + wizard.getName() + "].");
    } else {
        wizardElement.setModel(main.getLookup());
    }
}

From source file:net.firejack.platform.core.store.process.UserActorStore.java

License:Apache License

/**
 * @param caseId      - ID of the case// ww  w. j a v  a2  s.  co m
 * @param userId      - ID of the user to be assigned
 * @param actorLookup - actor lookup
 * @return return s true if user assigned to actor sucessfully. Otherwise returns false
 * @see IUserActorStore#assignUserToActor(Long, String, Integer)
 */
@Override
@Transactional
public boolean assignUserToActor(Long caseId, Long userId, String actorLookup) {
    boolean result = false;
    if (StringUtils.isNotBlank(actorLookup) && userId != null) {
        ActorModel actor = actorStore.findByLookup(actorLookup);
        if (actor != null) {
            if (!Hibernate.isInitialized(actor.getUserActors())) {
                Hibernate.initialize(actor.getUserActors());
            }
            List<UserActorModel> userActors = actor.getUserActors();
            boolean notFound = true;
            if (userActors != null) {
                for (UserActorModel userActor : userActors) {
                    if (userId.equals(userActor.getUser().getId())) {
                        notFound = false;
                        break;
                    }
                }
            }
            if (notFound) {
                UserModel user = userStore.findById(userId);
                CaseModel processCase = caseId == null ? null : caseStore.findById(caseId);
                UserActorModel userActor = new UserActorModel();
                userActor.setActor(actor);
                userActor.setUser(user);
                userActor.setCase(processCase);
                saveOrUpdate(userActor);
            }
            result = true;
        }
    }
    return result;
}

From source file:net.firejack.platform.core.store.registry.ActorStore.java

License:Apache License

/**
 * @param caseId - ID of the case//from   w ww  .  jav  a2  s .co  m
 * @return
 * @see IActorStore#findCaseAssigneeList(java.lang.Long)
 */
@Override
@Transactional(readOnly = true)
public List<UserModel> findCaseAssigneeList(Long caseId) {
    CaseModel processCase = getHibernateTemplate().get(CaseModel.class, caseId);
    if (processCase == null) {
        throw new BusinessFunctionException("Process case with id = " + caseId + " was not found.");
    }
    ProcessModel process = processCase.getProcess();
    List<ActivityModel> activities = process.getActivities();
    if (!Hibernate.isInitialized(activities)) {
        Hibernate.initialize(activities);
    }
    List<UserModel> assigneeList;
    if (activities == null || activities.isEmpty()) {
        assigneeList = null;
    } else {
        ActivityModel firstActivity = activities.get(0);
        assigneeList = userStore.findUsersBelongingToActor(firstActivity.getActor().getId());
    }
    return assigneeList;
}

From source file:net.firejack.platform.core.store.registry.ActorStore.java

License:Apache License

/**
 * @param caseId - ID of the case//from   w ww.  jav  a  2 s.co m
 * @param next   - flag showing whether the assignees should be listed for previous, current or next task
 * @return
 * @see IActorStore#findCaseAssigneeList(java.lang.Long)
 */
@Override
@Transactional(readOnly = true)
public List<UserModel> findCaseAssigneeList(Long caseId, Boolean next) {
    CaseModel processCase = getHibernateTemplate().get(CaseModel.class, caseId);
    if (processCase == null) {
        throw new BusinessFunctionException("Process case with id = " + caseId + " was not found.");
    }
    List<UserModel> assigneeList;
    if (processCase.getActive() == Boolean.TRUE) {
        if (!Hibernate.isInitialized(processCase.getTaskModels())) {
            Hibernate.initialize(processCase.getTaskModels());
        }
        TaskModel activeTaskModel = null;
        for (TaskModel taskModel : processCase.getTaskModels()) {
            if (taskModel.getActive()) {
                activeTaskModel = taskModel;
                break;
            }
        }
        if (activeTaskModel == null) {
            throw new BusinessFunctionException("Failed to find active task for case with id = " + caseId);
        } else {
            assigneeList = getTaskAssigneeList(activeTaskModel, next);
        }
    } else {
        assigneeList = new ArrayList<UserModel>();
        logger.warn("Trying to find assignee list for not active case.");
    }

    return assigneeList;
}

From source file:net.firejack.platform.core.store.registry.ActorStore.java

License:Apache License

/**
 * Gets the list of the users assigned to the task
 *
 * @param taskModel - task the users are assigned to
 * @param next - flag showing whether the assignees should be listed for previous, current or next taskModel
 * @return list of assigned users/*from w  w w  . ja v  a  2 s.  c  om*/
 */
private List<UserModel> getTaskAssigneeList(TaskModel taskModel, Boolean next) {
    List<UserModel> assigneeList;
    if (next == null) {
        ActivityModel activity = taskModel.getActivity();
        assigneeList = userStore.findUsersBelongingToActor(activity.getActor().getId());
    } else {
        List<ActivityModel> activities = taskModel.getCase().getProcess().getActivities();
        if (!Hibernate.isInitialized(activities)) {
            Hibernate.initialize(activities);
        }
        if (activities == null || activities.isEmpty()) {
            assigneeList = null;
        } else {
            ActivityModel activity = taskModel.getActivity();
            ActivityModel requiredActivity = null;
            if (next) {
                boolean activityPassed = false;
                for (ActivityModel act : activities) {
                    if (activityPassed && !act.getActivityType().equals(ActivityType.SYSTEM)) {
                        requiredActivity = act;
                        break;
                    }
                    if (act.equals(activity)) {
                        activityPassed = true;
                    }
                }
            } else {
                ActivityModel previousActivity = null;
                for (ActivityModel act : activities) {
                    if (act.equals(activity)) {
                        requiredActivity = previousActivity;
                        break;
                    }
                    if (!act.getActivityType().equals(ActivityType.SYSTEM)) {
                        previousActivity = act;
                    }
                }
            }
            if (requiredActivity == null) {
                logger.error("Required activity was not found.");
                assigneeList = null;
            } else {
                assigneeList = userStore.findUsersBelongingToActor(requiredActivity.getActor().getId());
            }
        }
    }
    return assigneeList;
}