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.VmwareNetworkProcess.java

/**
 * TODO: /*from   ww  w.ja  v  a 2 s. c o m*/
 *
 * @param vmwareProcessClient
 * @param instanceNo
 */
public void changeEthernetCard(VmwareProcessClient vmwareProcessClient, Long instanceNo) {
    VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo);

    // VirtualMachine
    VirtualMachine machine = vmwareProcessClient.getVirtualMachine(vmwareInstance.getMachineName());

    // VirtualEthernetCard?
    VirtualMachineConfigInfo configInfo = machine.getConfig();
    List<VirtualEthernetCard> ethernetCards = new ArrayList<VirtualEthernetCard>();
    for (VirtualDevice device : configInfo.getHardware().getDevice()) {
        if (device instanceof VirtualEthernetCard) {
            ethernetCards.add(VirtualEthernetCard.class.cast(device));
        }
    }

    // Key??
    Collections.sort(ethernetCards, new Comparator<VirtualEthernetCard>() {
        @Override
        public int compare(VirtualEthernetCard o1, VirtualEthernetCard o2) {
            return o1.getKey() - o2.getKey();
        }
    });

    // ???VirtualEthernetCard?
    List<VirtualEthernetCard> newEthernetCards = createEthernetCards(vmwareProcessClient, instanceNo, machine);

    // ?
    List<VirtualDeviceConfigSpec> deviceConfigSpecs = new ArrayList<VirtualDeviceConfigSpec>();

    for (int i = 0; i < newEthernetCards.size(); i++) {
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        VirtualEthernetCard newEthernetCard = newEthernetCards.get(i);
        deviceConfigSpec.setDevice(newEthernetCard);

        if (i < ethernetCards.size()) {
            // ?VirtualEthernetCard??????????
            VirtualEthernetCard ethernetCard = ethernetCards.get(i);
            // ???
            if (checkSameNormalNetwork(ethernetCard, newEthernetCard)) {
                continue;
            }
            // ???
            if (checkSameDistributedNetwork(ethernetCard, newEthernetCard)) {
                continue;
            }

            // VirtualEthernetCard?
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
            newEthernetCard.setKey(ethernetCard.getKey());
        } else {
            // ?VirtualEthernetCard?
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
        }

        deviceConfigSpecs.add(deviceConfigSpec);
    }

    // ??????
    if (deviceConfigSpecs.isEmpty()) {
        return;
    }

    VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    configSpec
            .setDeviceChange(deviceConfigSpecs.toArray(new VirtualDeviceConfigSpec[deviceConfigSpecs.size()]));

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

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100443", vmwareInstance.getMachineName()));
    }

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

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

    if (taskInfo.getState() != TaskInfoState.success) {
        // ??????
        AutoException exception = new AutoException("EPROCESS-000514", vmwareInstance.getMachineName());
        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-100444", vmwareInstance.getMachineName()));
    }
}

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

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

    // ???//w  w w .  java 2  s.  com
    VirtualMachineRuntimeInfo runtimeInfo = machine.getRuntime();
    if (runtimeInfo.getPowerState() == VirtualMachinePowerState.poweredOn) {
        return;
    }

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

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

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

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

    if (taskInfo.getState() != TaskInfoState.success) {
        // ?????
        AutoException exception = new AutoException("EPROCESS-000506", 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-100412", machineName));
    }
}

From source file:edu.utah.further.fqe.impl.domain.SearchQueryEntity.java

/**
 * @see java.lang.Object#toString()/*from   w w  w .  ja  v a 2  s  .  c  o  m*/
 */
@Override
public final String toString() {
    return ReflectionToStringBuilder.toString(this);
}

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

public InstanceDto waitRunInstance(String instanceId) {
    // TODO: API??RunInstances???????????????????????
    long timeout = 600 * 1000L;
    long startTime = System.currentTimeMillis();
    while (true) {
        boolean exist = false;
        List<Instance> instances = describeAllInstances();
        for (Instance instance : instances) {
            if (StringUtils.equals(instanceId, instance.getInstanceId())) {
                exist = true;//from ww  w  . j  a v a 2s .c o m
                break;
            }
        }
        if (exist) {
            break;
        }

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

    InstanceDto instance = waitInstance(instanceId);

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

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

    return instance;
}

From source file:jp.primecloud.auto.puppet.PuppetClient.java

protected CommandResult execute(List<String> commands) {
    if (log.isDebugEnabled()) {
        log.debug(commands);//from  w w  w.j  a va2s .com
    }

    // ??????
    long timeout = Long.MAX_VALUE;

    CommandResult result = CommandUtils.execute(commands, timeout);

    if (log.isDebugEnabled()) {
        log.debug(ReflectionToStringBuilder.toString(result));
    }

    return result;
}

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

public RunningInstancesItemType waitStartInstance(String instanceId) {
    // TODO: API??StartInstances?stopped?????????stopped?????
    long timeout = 600 * 1000L;
    long startTime = System.currentTimeMillis();
    while (true) {
        RunningInstancesItemType instance = describeInstance(instanceId);
        if (!"stopped".equals(instance.getInstanceState().getName())) {
            break;
        }/*w w  w.j  a v a  2s  . co  m*/

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

    RunningInstancesItemType instance = waitInstance(instanceId);

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

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

    return instance;
}

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

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

    // ???//from   w  ww . jav a 2s.c  om
    VirtualMachineRuntimeInfo runtimeInfo = machine.getRuntime();
    if (runtimeInfo.getPowerState() == VirtualMachinePowerState.poweredOff) {
        return;
    }

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

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

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

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

    if (taskInfo.getState() != TaskInfoState.success) {
        // ?????
        AutoException exception = new AutoException("EPROCESS-000507", 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-100414", machineName));
    }
}

From source file:jp.primecloud.auto.common.component.DnsStrategy.java

protected CommandResult execute(List<String> commands, List<String> stdins) {
    if (log.isDebugEnabled()) {
        log.debug(commands);//w  ww . j  a v a  2 s . c om
        log.debug(stdins);
    }

    CommandResult result = CommandUtils.execute(commands, stdins);

    if (log.isDebugEnabled()) {
        log.debug(ReflectionToStringBuilder.toString(result));
    }

    return result;
}

From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java

@TriggersRemove(cacheName = { "EmployeeCache", "GroupCache",
        "EmployeeKeyedByGroupCache" }, when = When.AFTER_METHOD_INVOCATION, removeAll = true, keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false")))
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class)
public void updateAllEmployee(List<EmployeeBO> employeeListFromLDAP) throws ExceptionWrapper {
    try {/*from  w  w w.j a  va2 s .  c  o m*/
        String messageTemplateAdded = "<html>\n" + "<head>\n" + "</head>\n" + "\n"
                + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n"
                + "  <p>A new user is added to the system.</p>\n" + "</blockquote>\n" + "<ul>\n"
                + "  <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n"
                + "<p>Please take necessary actions.</p>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n"
                + "  <p>Perceptive Kolkata Central</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>";

        String messageTemplateDeleted = "<html>\n" + "<head>\n" + "</head>\n" + "\n"
                + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n"
                + "  <p>An  user is removed from the system.</p>\n" + "</blockquote>\n" + "<ul>\n"
                + "  <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n"
                + "<p>Please take necessary actions.</p>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n"
                + "  <p>Perceptive Kolkata Central</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>";

        LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = employeeDataAccessor.getAllEmployees();
        for (EmployeeBO employeeBO : employeeListFromLDAP) {
            if (!employeeLinkedHashMap.containsKey(Long.valueOf(employeeBO.getEmployeeId()))) {
                //Add a new employee
                Employee employee = new Employee();
                employee.setEmployeeId(Long.parseLong(employeeBO.getEmployeeId()));
                employee.setEmail(employeeBO.getEmail());
                employee.setEmployeeName(employeeBO.getEmployeeName());
                employee.setEmployeeUid(employeeBO.getEmployeeUid());
                employee.setJobTitle(employeeBO.getJobTitle());
                employee.setMobileNumber(employeeBO.getMobileNumber());
                employee.setManager(employeeBO.getManager());
                employee.setManagerEmail(employeeBO.getManagerEmail());
                employee.setExtensionNum(employeeBO.getExtensionNum());
                employee.setWorkspace(employeeBO.getWorkspace());
                employee.setIsActive(true);
                employeeDataAccessor.addEmployee(employee);
                LoggingHelpUtil.printDebug(String.format("Adding user ----> %s with details %s %s",
                        employeeBO.getEmployeeName(), System.getProperty("line.separator"),
                        ReflectionToStringBuilder.toString(employeeBO)));
                //Send the mail
                HtmlEmail emailToSend = new HtmlEmail();
                emailToSend.setHostName(email.getHostName());
                String messageToSend = String.format(messageTemplateAdded, employeeBO.getEmployeeName(),
                        employeeBO.getEmployeeUid(), employeeBO.getEmployeeId().toString(),
                        employeeBO.getEmail(), employeeBO.getMobileNumber(), employeeBO.getJobTitle());

                emailToSend.setHtmlMsg(messageToSend);
                //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend));
                emailToSend.getToAddresses().clear();
                //Send mail to scrum masters and Development Managers Group Id 15
                Collection<EmployeeBO> allEmployeesNeedToGetMail = CollectionUtils.union(
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14")),
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("15")));
                for (EmployeeBO item : allEmployeesNeedToGetMail) {
                    emailToSend.addTo(item.getEmail(), item.getEmployeeName());
                }
                emailToSend.addTo(employeeBO.getManagerEmail(), employeeBO.getManager());//Send the mail to manager
                //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central");
                emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata");
                emailToSend.setSubject(String.format("New employee added : %s", employeeBO.getEmployeeName()));
                emailToSend.send();
                //==========================Mail send ends here===========================================================================================================
                //sendMailToPerceptiveOpsTeam(employeeBO);//Send mail to operations team in Shawnee
            } else {
                //Update a new employee
                employeeDataAccessor.updateEmployee(employeeBO);
                LoggingHelpUtil.printDebug(String.format("Updating user ----> %s with details %s %s",
                        employeeBO.getEmployeeName(), System.getProperty("line.separator"),
                        ReflectionToStringBuilder.toString(employeeBO)));
            }

            //========================================================================================================================================
        }
        //Delete employees if any
        for (Object obj : employeeLinkedHashMap.values()) {
            final EmployeeBO emp = (EmployeeBO) obj;
            if (!CollectionUtils.exists(employeeListFromLDAP, new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return emp.getEmployeeId().trim().equalsIgnoreCase(((EmployeeBO) o).getEmployeeId().trim()); //To change body of implemented methods use File | Settings | File Templates.
                }
            })) {
                emp.setActive(false); //Soft delete the Employee
                employeeDataAccessor.updateEmployee(emp);//Rest deletion will be taken care by the Trigger AFTER_EMPLOYEE_UPDATE
                LoggingHelpUtil.printDebug(
                        String.format("Deleting user ----> %s with details %s %s", emp.getEmployeeName(),
                                System.getProperty("line.separator"), ReflectionToStringBuilder.toString(emp)));
                //Send the mail
                HtmlEmail emailToSend = new HtmlEmail();
                emailToSend.setHostName(email.getHostName());

                String messageToSend = String.format(messageTemplateDeleted, emp.getEmployeeName(),
                        emp.getEmployeeUid(), emp.getEmployeeId().toString(), emp.getEmail(),
                        emp.getMobileNumber(), emp.getJobTitle());
                emailToSend.setHtmlMsg(messageToSend);
                //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend));
                emailToSend.getToAddresses().clear();
                //Send mail to scrum masters ==Group ID 14 and Development Managers Group Id 15
                Collection<EmployeeBO> allEmployeesNeedToGetMail = CollectionUtils.union(
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14")),
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("15")));
                for (EmployeeBO item : allEmployeesNeedToGetMail) {
                    emailToSend.addTo(item.getEmail(), item.getEmployeeName());
                }
                //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central");
                emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata");
                emailToSend.setSubject(String.format("Employee removed : %s", emp.getEmployeeName()));
                emailToSend.send();
            }
        }

        luceneUtil.indexUserInfo(getAllEmployees().values());

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

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

public InstanceDto waitStartInstance(String instanceId) {
    // TODO: API??StartInstances?stopped?????????stopped?????
    long timeout = 600 * 1000L;
    long startTime = System.currentTimeMillis();
    while (true) {
        InstanceDto instance = describeInstance(instanceId);
        if (!"stopped".equals(instance.getState().getName())) {
            break;
        }//from   w ww .j av  a 2 s .co  m

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

    InstanceDto instance = waitInstance(instanceId);

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

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

    return instance;
}