Example usage for org.apache.commons.lang.builder ReflectionToStringBuilder toString

List of usage examples for org.apache.commons.lang.builder ReflectionToStringBuilder toString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ReflectionToStringBuilder toString.

Prototype

public static String toString(Object object) 

Source Link

Document

Builds a toString value using the default ToStringStyle through reflection.

Usage

From source file:jp.primecloud.auto.process.vmware.VmwareProcessClient.java

public void destroyVM(String machineName) {
    // VirtualMachine
    VirtualMachine machine = getVirtualMachine(machineName);

    // ?/*from  w  w  w .  j a v a  2s.  com*/
    Task task;
    try {
        task = machine.destroy_Task();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000508", e, machineName);
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100423", machineName));
    }

    // ????
    try {
        task.waitForTask();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000508", e, machineName);
    } catch (InterruptedException ignore) {
    }

    // ??
    TaskInfo taskInfo;
    try {
        taskInfo = task.getTaskInfo();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000508", e, machineName);
    }

    if (taskInfo.getState() != TaskInfoState.success) {
        // ?????
        AutoException exception = new AutoException("EPROCESS-000508", machineName);
        if (taskInfo.getError() != null) {
            exception.addDetailInfo(ReflectionToStringBuilder.toString(taskInfo.getError().getFault()));
            exception.addDetailInfo(taskInfo.getError().getLocalizedMessage());
        }
        throw exception;
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100424", machineName));
    }
}

From source file:jp.primecloud.auto.process.nifty.NiftyProcessClient.java

public RunningInstancesItemType waitStopInstance(String instanceId) {
    // TODO: API??StopInstances?running?????????running?????
    long timeout = 600 * 1000L;
    long startTime = System.currentTimeMillis();
    while (true) {
        RunningInstancesItemType instance = describeInstance(instanceId);
        if (!"running".equals(instance.getInstanceState().getName())) {
            break;
        }/*from  w w w.  jav  a  2 s . c o  m*/

        if (System.currentTimeMillis() - startTime > timeout) {
            // ?????????
            throw new AutoException("EPROCESS-000613", instanceId);
        }
    }

    RunningInstancesItemType instance = waitInstance(instanceId);

    String state = instance.getInstanceState().getName();
    if (!"stopped".equals(state)) {
        // ?
        AutoException exception = new AutoException("EPROCESS-000614", instanceId, state);
        exception.addDetailInfo("result=" + ReflectionToStringBuilder.toString(instance));
        throw exception;
    }

    // 
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100516", instanceId));
    }

    return instance;
}

From source file:de.hybris.platform.commercefacades.customergroups.CustomerGroupFacadeIntegrationTest.java

@Test
public void testGetCustomerGroupForCurrentUser()
        throws UnknownIdentifierException, IllegalArgumentException, DuplicateUidException {
    final String userLogin = generateUniqueLogin();
    final UserGroupModel customerGroup = userGroupDao.findUserGroupByUid(CUSTOMER_GROUP_UID);
    final String userGroup2Uid = "userGroup2Uid";
    final String userGroup2Name = "userGroup2Name";
    customerGroupFacade.createCustomerGroup(userGroup2Uid, userGroup2Name);
    final UserGroupModel secondCustomerGroup = userGroupDao.findUserGroupByUid(userGroup2Uid);

    final UserModel user = registerUser(userLogin);
    userService.setCurrentUser(user);/*from w w w.  j  a v  a  2s  .co m*/
    // Customer gets added to 'customergroup' by default
    List<UserGroupData> allGroupsForUser = customerGroupFacade.getCustomerGroupsForCurrentUser();
    Assert.assertEquals(ReflectionToStringBuilder.toString(allGroupsForUser), 0, allGroupsForUser.size());

    customerGroupFacade.addUserToCustomerGroup(customerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForCurrentUser();
    Assert.assertEquals(1, allGroupsForUser.size());
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, customerGroup);

    customerGroupFacade.addUserToCustomerGroup(secondCustomerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForCurrentUser();
    Assert.assertEquals(2, allGroupsForUser.size());
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, customerGroup);
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, secondCustomerGroup);

    customerGroupFacade.removeUserFromCustomerGroup(secondCustomerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForCurrentUser();
    Assert.assertEquals(1, allGroupsForUser.size());
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, customerGroup);

    customerGroupFacade.removeUserFromCustomerGroup(customerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForCurrentUser();
    Assert.assertEquals(0, allGroupsForUser.size());

    // check that getCustomerGroupsForCurrentUser does not return user groups which are not customer groups 
    final UserGroupModel notCustomerGroup = createUserGroup("notCustomerGroup");
    final Set<PrincipalModel> members = new HashSet<PrincipalModel>();
    members.add(user);
    notCustomerGroup.setMembers(members);
    modelService.save(notCustomerGroup);
    modelService.refresh(user);
    Assert.assertEquals(1, user.getGroups().size());
    Assert.assertTrue(user.getGroups().contains(notCustomerGroup));
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForCurrentUser();
    Assert.assertEquals(0, allGroupsForUser.size());
}

From source file:jp.primecloud.auto.process.vmware.VmwareProcessClient.java

public void changeResourceVM(String machineName, Integer cpu, Long memory) {
    // VirtualMachine
    VirtualMachine machine = getVirtualMachine(machineName);

    // //from   www . ja v  a  2 s  .  co  m
    VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    configSpec.setNumCPUs(cpu);
    configSpec.setMemoryMB(memory);

    // 
    Task task;
    try {
        task = machine.reconfigVM_Task(configSpec);
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000513", e, machineName);
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100433", machineName));
    }

    // ????
    try {
        task.waitForTask();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000513", e, machineName);
    } catch (InterruptedException ignore) {
    }

    // ??
    TaskInfo taskInfo;
    try {
        taskInfo = task.getTaskInfo();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000513", e, machineName);
    }

    if (taskInfo.getState() != TaskInfoState.success) {
        // ??????
        AutoException exception = new AutoException("EPROCESS-000513", machineName);
        if (taskInfo.getError() != null) {
            exception.addDetailInfo(ReflectionToStringBuilder.toString(taskInfo.getError().getFault()));
            exception.addDetailInfo(taskInfo.getError().getLocalizedMessage());
        }
        throw exception;
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100434", machineName));
    }
}

From source file:jp.primecloud.auto.nifty.process.NiftyProcessClient.java

public InstanceDto waitStopInstance(String instanceId) {
    // TODO: API??StopInstances?running?????????running?????
    long timeout = 600 * 1000L;
    long startTime = System.currentTimeMillis();
    while (true) {
        InstanceDto instance = describeInstance(instanceId);
        if (!"running".equals(instance.getState().getName())) {
            break;
        }//from  w  ww  .  ja v  a  2 s .  c  o  m

        if (System.currentTimeMillis() - startTime > timeout) {
            // ?????????
            throw new AutoException("EPROCESS-000613", instanceId);
        }
    }

    InstanceDto instance = waitInstance(instanceId);

    String state = instance.getState().getName();
    if (!"stopped".equals(state)) {
        // ?
        AutoException exception = new AutoException("EPROCESS-000614", instanceId, state);
        exception.addDetailInfo("result=" + ReflectionToStringBuilder.toString(instance));
        throw exception;
    }

    // 
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100516", instanceId));
    }

    return instance;
}

From source file:jp.primecloud.auto.process.vmware.VmwareProcessClient.java

public void setExtraConfigVM(String machineName, Map<String, Object> extraConfigs) {
    // VirtualMachine
    VirtualMachine machine = getVirtualMachine(machineName);

    // ExtraConfig?
    List<OptionValue> optionValues = new ArrayList<OptionValue>();
    for (Map.Entry<String, Object> entry : extraConfigs.entrySet()) {
        OptionValue optionValue = new OptionValue();
        optionValue.setKey(entry.getKey());
        optionValue.setValue(entry.getValue());
        optionValues.add(optionValue);/*  www .  ja  va2  s.  co  m*/
    }

    // 
    VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    configSpec.setExtraConfig(optionValues.toArray(new OptionValue[optionValues.size()]));

    // ?
    Task task;
    try {
        task = machine.reconfigVM_Task(configSpec);
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000523", e, machineName);
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100435", machineName));
    }

    // ????
    try {
        task.waitForTask();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000523", e, machineName);
    } catch (InterruptedException ignore) {
    }

    // ??
    TaskInfo taskInfo;
    try {
        taskInfo = task.getTaskInfo();
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000523", e, machineName);
    }

    if (taskInfo.getState() != TaskInfoState.success) {
        // ?????
        AutoException exception = new AutoException("EPROCESS-000523", machineName);
        if (taskInfo.getError() != null) {
            exception.addDetailInfo(ReflectionToStringBuilder.toString(taskInfo.getError().getFault()));
            exception.addDetailInfo(taskInfo.getError().getLocalizedMessage());
        }
        throw exception;
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100436", machineName));
    }
}

From source file:jp.primecloud.auto.nifty.process.NiftyProcessClient.java

public VolumeDto waitCreateVolume(String volumeId) {
    // ???//from  w  w  w  .java  2s .  c o m
    VolumeDto volume = null;
    volume = waitVolume(volumeId);

    String status = volume.getStatus();
    if (!"in-use".equals(status)) {
        // ?
        AutoException exception = new AutoException("EPROCESS-000621", volumeId, status);
        exception.addDetailInfo("result=" + ReflectionToStringBuilder.toString(volume));
        throw exception;
    }

    // 
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100522", volumeId));
    }

    return volume;
}

From source file:com.tobedevoured.modelcitizen.ModelFactory.java

/**
 * Create a Model for a registered {@link Blueprint} using {@link Erector}.
 * Values set in the model will not be overridden by defaults in the
 * {@link Blueprint}.//from  www .j  a  va 2 s. c o m
 *
 * @param erector        {@link Erector}
 * @param referenceModel T the reference model instance, or null
 * @param withPolicies   boolean if Policies should be applied to the create
 * @return T new Model
 * @throws CreateModelException
 */
public <T> T createModel(Erector erector, T referenceModel, boolean withPolicies) throws CreateModelException {

    erector.clearCommands();

    T createdModel;
    try {
        createdModel = (T) createNewInstance(erector);
    } catch (BlueprintTemplateException e) {
        throw new CreateModelException(e);
    }

    logger.trace("Created model {} from {} based on {}",
            new Object[] { createdModel, erector, referenceModel });

    final T nonNullReferenceModel = referenceModel == null ? createdModel : referenceModel;
    erector.setReference(nonNullReferenceModel);

    if (withPolicies) {
        List<BlueprintPolicy> blueprintPolicies = this.getBlueprintPolicies().get(erector.getTarget());
        if (blueprintPolicies != null) {

            logger.debug("  Running Blueprint policies");

            for (BlueprintPolicy policy : blueprintPolicies) {
                Map<ModelField, Set<Command>> modelFieldCommands = null;
                try {
                    logger.info("    processing {}", policy);
                    modelFieldCommands = policy.process(this, erector, createdModel);

                } catch (PolicyException e) {
                    new CreateModelException(e);
                }

                for (ModelField modelField : modelFieldCommands.keySet()) {
                    erector.addCommands(modelField, modelFieldCommands.get(modelField));
                }
            }
        }
    }

    for (ModelField modelField : erector.getModelFields()) {

        logger.trace("ModelField {}", ReflectionToStringBuilder.toString(modelField));

        Object value = null;

        if (withPolicies) {
            List<FieldPolicy> policiesForSingleField = this.getFieldPolicies().get(modelField.getTarget());
            if (policiesForSingleField != null) {

                logger.debug("  Running Field policies");

                for (FieldPolicy policy : policiesForSingleField) {
                    try {
                        logger.info("    processing {} for {}", policy, modelField.getTarget());
                        Command command = policy.process(this, erector, modelField, createdModel);
                        if (command != null) {
                            erector.addCommand(modelField, command);
                        }
                    } catch (PolicyException e) {
                        new CreateModelException(e);
                    }
                }
            }
        }

        if (erector.getCommands(modelField).size() > 0) {
            logger.debug("  ModelField commands: {}", erector.getCommands(modelField));
        }

        if (!erector.getCommands(modelField).contains(Command.SKIP_INJECTION)) {

            // Process DefaultField
            if (modelField instanceof DefaultField) {

                DefaultField defaultField = (DefaultField) modelField;

                if (!erector.getCommands(modelField).contains(Command.SKIP_REFERENCE_INJECTION)) {
                    try {
                        value = erector.getTemplate().get(nonNullReferenceModel, defaultField.getName());
                    } catch (BlueprintTemplateException e) {
                        throw new CreateModelException(e);
                    }
                }

                // If null or the field forces, use value set in blueprint, otherwise
                // use the value of the reference model
                if (!erector.getCommands(modelField).contains(Command.SKIP_BLUEPRINT_INJECTION)
                        && (value == null || defaultField.isForce())) {
                    value = defaultField.getValue();
                }

                // If value is an instance of FieldCallBack, eval the callback and use the value
                if (value != null && value instanceof Getable) {
                    Getable callBack = (Getable) value;
                    value = callBack.get(nonNullReferenceModel);
                }

                try {
                    createdModel = erector.getTemplate().set(createdModel, defaultField.getName(), value);
                } catch (BlueprintTemplateException e) {
                    throw new CreateModelException(e);
                }

                // Process MappedField
            } else if (modelField instanceof MappedField) {

                MappedField mappedField = (MappedField) modelField;

                if (!erector.getCommands(modelField).contains(Command.SKIP_REFERENCE_INJECTION)) {
                    try {
                        value = erector.getTemplate().get(nonNullReferenceModel, mappedField.getName());
                    } catch (BlueprintTemplateException e) {
                        throw new CreateModelException(e);
                    }
                }

                if (!erector.getCommands(modelField).contains(Command.SKIP_BLUEPRINT_INJECTION) && value == null
                        && !mappedField.isNullable()) {
                    value = this.createModel(mappedField.getTarget());
                }

                try {
                    createdModel = erector.getTemplate().set(createdModel, mappedField.getName(), value);
                } catch (BlueprintTemplateException e) {
                    throw new CreateModelException(e);
                }

                // Process MappedListField
            } else if (modelField instanceof MappedListField) {

                MappedListField listField = (MappedListField) modelField;

                List modelList = null;
                try {
                    value = (List) erector.getTemplate().construct(listField.getTargetList());
                } catch (BlueprintTemplateException e) {
                    throw new CreateModelException(e);
                }

                if (!erector.getCommands(modelField).contains(Command.SKIP_INJECTION)) {
                    try {
                        modelList = (List) erector.getTemplate().get(nonNullReferenceModel,
                                listField.getName());
                    } catch (BlueprintTemplateException e) {
                        throw new CreateModelException(e);
                    }
                }

                if (!erector.getCommands(modelField).contains(Command.SKIP_BLUEPRINT_INJECTION)) {
                    // Inject models into List If list is null or force is true or it is an empty list that is ignored
                    if ((modelList == null || listField.isForce())
                            || (modelList.size() == 0 && !listField.isIgnoreEmpty())) {
                        for (int x = 0; x < listField.getSize(); x++) {
                            ((List) value).add(this.createModel(listField.getTarget()));
                        }

                    } else {
                        for (Object object : modelList) {
                            ((List) value).add(this.createModel(object));
                        }
                    }
                }

                try {
                    createdModel = erector.getTemplate().set(createdModel, listField.getName(), value);
                } catch (BlueprintTemplateException e) {
                    throw new CreateModelException(e);
                }

                // Process MappedSetField
            } else if (modelField instanceof MappedSetField) {

                MappedSetField setField = (MappedSetField) modelField;

                try {
                    value = erector.getTemplate().construct(setField.getTargetSet());
                } catch (BlueprintTemplateException e) {
                    throw new CreateModelException(e);
                }

                Set referenceModelSet = null;
                if (!erector.getCommands(modelField).contains(Command.SKIP_INJECTION)) {
                    try {
                        referenceModelSet = (Set) erector.getTemplate().get(nonNullReferenceModel,
                                setField.getName());
                    } catch (BlueprintTemplateException e) {
                        throw new CreateModelException(e);
                    }
                }

                if (!erector.getCommands(modelField).contains(Command.SKIP_BLUEPRINT_INJECTION)) {
                    // Inject models into Set If list is null or force is true or it is an empty set that is ignored
                    if ((referenceModelSet == null || setField.isForce())
                            || (referenceModelSet.size() == 0 && !setField.isIgnoreEmpty())) {
                        for (int x = 0; x < setField.getSize(); x++) {
                            ((Set) value).add(this.createModel(setField.getTarget()));
                        }
                    } else {
                        for (Object object : referenceModelSet) {
                            ((Set) value).add(this.createModel(object));
                        }
                    }
                }

                try {
                    createdModel = erector.getTemplate().set(createdModel, setField.getName(), value);
                } catch (BlueprintTemplateException e) {
                    throw new CreateModelException(e);
                }
            }
        }
    }

    List<Callback> afterCreateCallbacks = erector.getCallbacks("afterCreate");
    if (afterCreateCallbacks != null) {
        for (Callback callback : afterCreateCallbacks) {
            if (callback instanceof AfterCreateCallback) {
                createdModel = ((AfterCreateCallback<T>) callback).afterCreate(createdModel);
            } else {
                // XXX: should this toss an exception?
                logger.error("Invalid AfterCreateCallback registered for {}", referenceModel.getClass());
            }
        }
    }

    return createdModel;
}

From source file:jp.primecloud.auto.nifty.process.NiftyProcessClient.java

protected VolumeDto waitVolume(String volumeId) {
    // Volume???/*w  w  w .  java  2s .c  o m*/
    String[] stableStatus = new String[] { "available", "in-use" };
    String[] unstableStatus = new String[] { "creating" };
    VolumeDto volume = null;
    while (true) {
        volume = describeVolume(volumeId);
        String status;
        status = volume.getStatus();

        if (ArrayUtils.contains(stableStatus, status)) {
            break;
        }

        if (!ArrayUtils.contains(unstableStatus, status)) {
            // ???
            AutoException exception = new AutoException("EPROCESS-000620", volumeId, status);
            exception.addDetailInfo("result=" + ReflectionToStringBuilder.toString(volume));
            throw exception;
        }
    }

    return volume;
}

From source file:de.hybris.platform.commercefacades.customergroups.CustomerGroupFacadeIntegrationTest.java

@Test
public void testGetCustomerGroupForUser()
        throws UnknownIdentifierException, IllegalArgumentException, DuplicateUidException {
    final String userLogin = generateUniqueLogin();
    final UserGroupModel customerGroup = userGroupDao.findUserGroupByUid(CUSTOMER_GROUP_UID);
    final String userGroup2Uid = "userGroup2Uid";
    final String userGroup2Name = "userGroup2Name";
    customerGroupFacade.createCustomerGroup(userGroup2Uid, userGroup2Name);
    final UserGroupModel secondCustomerGroup = userGroupDao.findUserGroupByUid(userGroup2Uid);
    final UserModel user = registerUser(userLogin);

    List<UserGroupData> allGroupsForUser = customerGroupFacade.getCustomerGroupsForUser(user.getUid());
    Assert.assertEquals(ReflectionToStringBuilder.toString(allGroupsForUser), 0, allGroupsForUser.size());

    customerGroupFacade.addUserToCustomerGroup(customerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForUser(user.getUid());
    Assert.assertEquals(1, allGroupsForUser.size());
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, customerGroup);

    customerGroupFacade.addUserToCustomerGroup(secondCustomerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForUser(user.getUid());
    Assert.assertEquals(2, allGroupsForUser.size());
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, customerGroup);
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, secondCustomerGroup);

    customerGroupFacade.removeUserFromCustomerGroup(secondCustomerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForUser(user.getUid());
    Assert.assertEquals(1, allGroupsForUser.size());
    assertThaUserGroupDataListContainEquivalentUserGroupModel(allGroupsForUser, customerGroup);

    customerGroupFacade.removeUserFromCustomerGroup(customerGroup.getUid(), user.getUid());
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForUser(userLogin);
    Assert.assertEquals(0, allGroupsForUser.size());

    // check that getCustomerGroupsForUser does not return user groups which are not customer groups 
    final UserGroupModel notCustomerGroup = createUserGroup("notCustomerGroup");
    final Set<PrincipalModel> members = new HashSet<PrincipalModel>();
    members.add(user);/* w w  w.j  a v  a  2s.co m*/
    notCustomerGroup.setMembers(members);
    modelService.save(notCustomerGroup);
    modelService.refresh(user);
    Assert.assertEquals(1, user.getGroups().size());
    Assert.assertTrue(user.getGroups().contains(notCustomerGroup));
    allGroupsForUser = customerGroupFacade.getCustomerGroupsForUser(userLogin);
    Assert.assertEquals(0, allGroupsForUser.size());
}