Example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang.builder ToStringBuilder reflectionToString

Introduction

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

Prototype

public static String reflectionToString(Object object, ToStringStyle style) 

Source Link

Document

Forwards to ReflectionToStringBuilder.

Usage

From source file:org.slc.sli.api.security.context.validator.StaffToStudentValidator.java

private Iterable<Entity> getStudentEntitiesFromIds(Collection<String> studentIds) {
    LOG.debug("StaffToStudentValidator.getStudentEntitiesFromIds()");
    LOG.debug("  studentIds: {}", (studentIds == null) ? "null"
            : ToStringBuilder.reflectionToString(studentIds, ToStringStyle.DEFAULT_STYLE));

    NeutralQuery studentQuery = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID,
            NeutralCriteria.CRITERIA_IN, new ArrayList<String>(studentIds)));
    studentQuery.setEmbeddedFieldString("schools");

    Iterable<Entity> students = null;
    students = getRepo().findAll(EntityNames.STUDENT, studentQuery);

    if (students == null) {
        LOG.debug("  students NOT found in Repo.");
    } else {/*from w  w w  . jav  a 2s . c om*/
        LOG.debug("  students WERE found in Repo.");
    }

    return students;
}

From source file:org.slc.sli.api.service.BasicService.java

/**
 * Retrieves an entity from the data store with certain fields added/removed.
 *
 * @param neutralQuery all parameters to be included in query
 * @return the body of the entity//  w  w w  . j  a v  a 2  s . co  m
 */
@Override
public Iterable<String> listIds(final NeutralQuery neutralQuery) {
    LOG.debug(">>>BasicService.listIds()");
    LOG.debug("  neutralQuery: "
            + ToStringBuilder.reflectionToString(neutralQuery, ToStringStyle.MULTI_LINE_STYLE));
    checkAccess(true, false, null);
    checkFieldAccess(neutralQuery, false);

    NeutralQuery nq = neutralQuery;
    injectSecurity(nq);
    Iterable<Entity> entities = repo.findAll(collectionName, nq);

    List<String> results = new ArrayList<String>();
    for (Entity entity : entities) {
        results.add(entity.getEntityId());
    }
    return results;
}

From source file:org.slc.sli.api.service.BasicServiceTest.java

@SuppressWarnings("unchecked")
@Test//from   www  .j ava2 s . c  o m
public void testCreate()
        throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    securityContextInjector.setEducatorContext();

    //adding this to research "Heisenbug" that may be related to timing of resource initialization, which causes nonrepeatable test failures.
    try {
        Thread.currentThread().sleep(5L); //sleep for 5 ms
    } catch (InterruptedException is) {
        //squish
    }

    RightAccessValidator mockAccessValidator = Mockito.mock(RightAccessValidator.class);
    Field rightAccessValidator = BasicService.class.getDeclaredField("rightAccessValidator");
    rightAccessValidator.setAccessible(true);
    rightAccessValidator.set(service, mockAccessValidator);

    //adding this to research "Heisenbug" that may be related to timing of resource initialization, which causes nonrepeatable test failures.
    try {
        Thread.currentThread().sleep(5L); //sleep for 5 ms
    } catch (InterruptedException is) {
        //squish
    }

    EntityBody entityBody1 = new EntityBody();
    entityBody1.put("studentUniqueStateId", "student1");
    EntityBody entityBody2 = new EntityBody();
    entityBody2.put("studentUniqueStateId", "student2");

    List<EntityBody> entityBodies = Arrays.asList(entityBody1, entityBody2);

    Entity entity1 = new MongoEntity("student", "student1", entityBody1, new HashMap<String, Object>());
    Entity entity2 = new MongoEntity("student", "student2", entityBody2, new HashMap<String, Object>());
    Mockito.when(mockRepo.create(Mockito.eq("student"), Mockito.eq(entityBody1), Mockito.any(Map.class),
            Mockito.eq("student"))).thenReturn(entity1);
    Mockito.when(mockRepo.create(Mockito.eq("student"), Mockito.eq(entityBody2), Mockito.any(Map.class),
            Mockito.eq("student"))).thenReturn(entity2);

    LOG.debug(ToStringBuilder.reflectionToString(entityBodies, ToStringStyle.MULTI_LINE_STYLE));

    //adding this to research "Heisenbug" that may be related to timing of resource initialization, which causes nonrepeatable test failures.
    try {
        Thread.currentThread().sleep(5L); //sleep for 5 ms
    } catch (InterruptedException is) {
        //squish
    }

    List<String> listResult = service.create(entityBodies);

    Assert.assertEquals("EntityBody mismatch", entity1.getEntityId(), listResult.toArray()[0]);
    Assert.assertEquals("EntityBody mismatch", entity2.getEntityId(), listResult.toArray()[1]);
}

From source file:org.slc.sli.dashboard.client.SDKAPIClient.java

@Override
public List<GenericEntity> searchStudents(String token, String query, Map<String, String> params) {
    LOG.info("searchStudents: " + query);
    LOG.info("params: " + ToStringBuilder.reflectionToString(params, ToStringStyle.MULTI_LINE_STYLE));

    //rreturn this.readEntityList(token, "search/students?q=" + query + "&" + this.buildQueryString(params));
    return this.readEntityList(token, SDKConstants.STUDENTS + "?" + SDKConstants.PARAM_LAST_NAME + "=~" + query
            + "&" + this.buildQueryString(params));
}

From source file:org.soaplab.services.metadata.AnalysisDef.java

/**************************************************************************
 *
 **************************************************************************/
public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

From source file:org.springmodules.xt.model.generator.factory.FactoryGeneratorInterceptor.java

private Object make() {
    logger.debug("Making object of class: " + this.productClass);

    int argsNr = this.constructorArgs.size();
    Object[] argsArray = new Object[argsNr];
    Class[] typesArray = new Class[argsNr];
    for (Map.Entry<Integer, ConstructorArgPair> entry : this.constructorArgs.entrySet()) {
        int position = entry.getKey();
        Object value = entry.getValue().getValue();
        Class type = entry.getValue().getType();
        if (position < 0 || position > argsNr - 1) {
            throw new IllegalArgumentPositionException("Illegal position: " + position);
        } else {/*w  w w  .  j a v  a  2  s  .c o  m*/
            argsArray[position] = value;
            typesArray[position] = type;
        }
    }

    try {
        Constructor constructor = this.productClass.getConstructor(typesArray);
        Object product = constructor.newInstance(argsArray);
        return product;
    } catch (NoSuchMethodException ex) {
        throw new ObjectConstructionException("No constructor found accepting the following array of types: "
                + ToStringBuilder.reflectionToString(typesArray, ToStringStyle.SIMPLE_STYLE)
                + " Have you correctly set all constructor arguments?", ex);
    } catch (InvocationTargetException ex) {
        throw new ObjectConstructionException(
                "Exception thrown by the underlying constructor: " + ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
        throw new ObjectConstructionException("Cannot access a constructor with the following array of types: "
                + ToStringBuilder.reflectionToString(typesArray, ToStringStyle.SIMPLE_STYLE)
                + " Have you correctly set all constructor arguments?", ex);
    } catch (InstantiationException ex) {
        throw new ObjectConstructionException("Unable to instantiate the following class: " + this.productClass,
                ex);
    }
}

From source file:org.xlcloud.rest.client.config.ExceptionHandlingClientFilter.java

@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
    ClientResponse r = getNext().handle(cr);
    int statusCode = r.getStatus();
    if (statusCode <= 300) {
        return r;
    } else {/*from www .  ja v  a2 s . c o m*/
        BaseException.ExceptionDetailsBase exceptionDetails = r
                .getEntity(BaseException.ExceptionDetailsBase.class);
        if (exceptionDetails != null) {
            LOG.error("Got client exception with details: "
                    + ToStringBuilder.reflectionToString(exceptionDetails, ToStringStyle.SHORT_PREFIX_STYLE));
            throwExceptionForStatusCode(statusCode, exceptionDetails);
        }
    }
    return r;
}

From source file:org.xlcloud.service.dao.VirtualClusterDefinitionsDaoTest.java

@Test
public void getAllModels() {
    LOG.info("Get all vcDefinition models test");
    Collection<VirtualClusterDefinitionModel> allVcDefinitions = vcDefinitionsDao.findAll();
    assertEquals(4, allVcDefinitions.size());

    for (VirtualClusterDefinitionModel model : allVcDefinitions) {
        LOG.info(ToStringBuilder.reflectionToString(model, ToStringStyle.MULTI_LINE_STYLE));
    }/*from  w w w.j  a v  a2 s.  c  o  m*/
}

From source file:org.xlcloud.service.dao.VirtualClusterDefinitionsDaoTest.java

@Test
public void getModelsById() {
    LOG.info("Get vcDefinition models by id test");
    Collection<VirtualClusterDefinitionModel> allVcDefinitions = vcDefinitionsDao.findAll();

    for (VirtualClusterDefinitionModel model : allVcDefinitions) {
        assertEquals(model, vcDefinitionsDao.find(model.getVcDefinitionId()));
        LOG.info(ToStringBuilder.reflectionToString(model, ToStringStyle.MULTI_LINE_STYLE));
    }/*from w ww  .  jav  a 2  s  .  c  o m*/
}

From source file:org.xlcloud.service.manager.VirtualClustersManagerImpl.java

/** {@inheritDoc} */
@Override/*from   www  .ja  va 2 s.  c o  m*/
public VirtualCluster addVirtualCluster(VirtualCluster virtualCluster) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Trying to create virtual cluster: "
                + ToStringBuilder.reflectionToString(virtualCluster, ToStringStyle.SHORT_PREFIX_STYLE));
    }
    // validate VC
    if (virtualCluster == null) {
        LOG.info("Request does not contain mandatory 'virtualCluster' object.");
        throw new VcmsValidationException("Request does not contain mandatory 'virtualCluster' object.");
    } else if (virtualCluster.getName() == null) {
        LOG.info("Virtual Cluster does not contain mandatory 'name' field");
        throw new VcmsValidationException("Virtual Cluster does not contain mandatory 'name' field");
    }
    Long projectId = virtualCluster.getProjectId();
    if (projectsManager.get(projectId) == null) {
        LOG.info("Virtual Cluster's project (id " + projectId + ") not found.");
        throw new VcmsObjectNotFoundException("project with id '" + projectId + "' not found");
    }

    VirtualClusterDefinition definition = getDefinitionForVirtualCluster(
            virtualCluster.getVirtualClusterDefinitionId());

    // Save required info in database
    VirtualClusterModel model = virtualClusterTransformer.transformFromDto(virtualCluster);
    // fill required fields
    if (model.getParameters() == null) {
        model.setParameters(new LinkedList<VirtualClusterParameterModel>());
    }
    VirtualClusterDefinitionModel vcdModel = vcdDao.find(model.getVirtualClusterDefinition().getId());
    // validate applications
    //        for(ApplicationModel applicationModel : model.getApplications()) {
    //            Application application = applicationsManager.getApplication(applicationModel.getId());
    //            validateRequirements(application, vcdModel);
    //        }
    model.setVirtualClusterDefinition(vcdModel);

    validateParameters(model.getParameters(), definition.getTemplate());
    completeParameters(model, definition.getTemplate());

    Project project = projectsManager.get(virtualCluster.getProjectId());
    model.setAccountId(project.getAccountId());

    if (clusterExists(virtualCluster)) {
        String message = "Cluster with name " + virtualCluster.getName() + " already exists in project "
                + virtualCluster.getProjectId();
        LOG.info(message);
        throw new VcmsDuplicatedEntityException(message);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating virtual cluster in IAM: " + model);
    }
    //TODO: przemyslec gdzie to id powinno byc
    //        model.setBackendId(iamCluster.getId().toString());

    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving virtual cluster model in database: " + model);
    }

    model = virtualClustersDao.createOrUpdate(model);
    virtualCluster.setId(model.getId());
    //TODO: check if we can just return iamVcManager
    return getVirtualCluster(model.getVirtualClusterId());
}