Search in sources :

Example 1 with PropertyAccessor

use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.

the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideTabletPrefix.

@Test
public void overrideTabletPrefix() throws Exception {
    PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.tabletPrefix:tab/");
    assertThat(accessor.getPropertyValue("tabletPrefix")).isEqualTo("tab/");
}
Also used : PropertyAccessor(org.springframework.beans.PropertyAccessor) Test(org.junit.Test)

Example 2 with PropertyAccessor

use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.

the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideNormalSuffix.

@Test
public void overrideNormalSuffix() throws Exception {
    PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.normalSuffix:.nor");
    assertThat(accessor.getPropertyValue("normalSuffix")).isEqualTo(".nor");
}
Also used : PropertyAccessor(org.springframework.beans.PropertyAccessor) Test(org.junit.Test)

Example 3 with PropertyAccessor

use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.

the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideMobilePrefix.

@Test
public void overrideMobilePrefix() throws Exception {
    PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.mobilePrefix:mob/");
    assertThat(accessor.getPropertyValue("mobilePrefix")).isEqualTo("mob/");
}
Also used : PropertyAccessor(org.springframework.beans.PropertyAccessor) Test(org.junit.Test)

Example 4 with PropertyAccessor

use of org.springframework.beans.PropertyAccessor in project summerb by skarpushin.

the class DataSetLoaderImpl method enumerateOutgoingReferences.

/**
 * @param scanForReferences
 *            dataSet to scan for Many2one & One2one referenced objects
 * @param checkForExistence
 *            data set that contains already loaded objects so that we can
 *            skip loading these objects again
 * @param references
 *            references to use
 * @return map entityTypeCode to list of ids of these entities to be loaded
 */
private Map<String, Set<Object>> enumerateOutgoingReferences(DataSet scanForReferences, DataSet checkForExistence, Ref[] references) {
    Map<String, Set<Object>> ret = new HashMap<>();
    for (DataTable table : scanForReferences.getTables().values()) {
        List<Ref> outgoingRefs = enumOutgoingRefsToTableOrNull(references, table.getName());
        if (outgoingRefs == null) {
            continue;
        }
        for (Object rowObj : table.getRows().values()) {
            HasId row = (HasId) rowObj;
            PropertyAccessor propertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(row);
            for (Ref ref : outgoingRefs) {
                Object referencedId = null;
                try {
                    referencedId = propertyAccessor.getPropertyValue(ref.getFromField());
                } catch (Throwable t) {
                    throw new RuntimeException("Failed to read property " + ref.getFromField() + " from " + row, t);
                }
                if (referencedId == null) {
                    continue;
                }
                if (checkForExistence.get(ref.getToEntity()).find(referencedId) != null) {
                    // that one is already loaded, skip
                    continue;
                }
                Set<Object> referencedIds = ret.get(ref.getToEntity());
                if (referencedIds == null) {
                    ret.put(ref.getToEntity(), referencedIds = new HashSet<>());
                }
                referencedIds.add(referencedId);
            }
        }
    }
    return ret;
}
Also used : DataTable(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable) HashSet(java.util.HashSet) Set(java.util.Set) DataSet(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet) PropertyAccessor(org.springframework.beans.PropertyAccessor) HashMap(java.util.HashMap) HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) Ref(org.summerb.approaches.jdbccrud.api.dto.relations.Ref) HashSet(java.util.HashSet)

Example 5 with PropertyAccessor

use of org.springframework.beans.PropertyAccessor in project summerb by skarpushin.

the class DataSetLoaderImpl method populateBackReferencesOne2Many.

private void populateBackReferencesOne2Many(EntityTypeToObjectsMap rowsMap, Map<Ref, Set<Object>> refs, DataSet dataSet) {
    for (Entry<String, List<HasId>> entry : rowsMap.entrySet()) {
        for (HasId row : entry.getValue()) {
            PropertyAccessor propertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(row);
            for (Ref ref : refs.keySet()) {
                if (!ref.getToEntity().equals(entry.getKey())) {
                    continue;
                }
                Object referencedId = null;
                try {
                    referencedId = propertyAccessor.getPropertyValue(ref.getToField());
                } catch (Throwable t) {
                    throw new RuntimeException("Failed to read property " + ref.getFromField() + " from " + row, t);
                }
                if (referencedId == null) {
                    continue;
                }
                RowIdToBackReferencesMap backRefs = dataSet.get(ref.getFromEntity()).getBackRefs();
                if (backRefs.get(referencedId) == null) {
                    backRefs.put(referencedId, new RefToReferencedObjectsIdsMap());
                }
                RefToReferencedObjectsIdsMap refToObjsMap = backRefs.get(referencedId);
                if (refToObjsMap.get(ref.getName()) == null) {
                    refToObjsMap.put(ref.getName(), new HashSet<>());
                }
                refToObjsMap.get(ref.getName()).add(row.getId());
            }
        }
    }
}
Also used : HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) Ref(org.summerb.approaches.jdbccrud.api.dto.relations.Ref) PropertyAccessor(org.springframework.beans.PropertyAccessor) RefToReferencedObjectsIdsMap(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable.RefToReferencedObjectsIdsMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) List(java.util.List) RowIdToBackReferencesMap(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable.RowIdToBackReferencesMap)

Aggregations

PropertyAccessor (org.springframework.beans.PropertyAccessor)13 Test (org.junit.Test)9 URI (java.net.URI)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 HttpMethod (org.springframework.http.HttpMethod)2 ResponseEntity (org.springframework.http.ResponseEntity)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 RestTemplate (org.springframework.web.client.RestTemplate)2 RequestAttributes (org.springframework.web.context.request.RequestAttributes)2 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)2 HasId (org.summerb.approaches.jdbccrud.api.dto.HasId)2 Ref (org.summerb.approaches.jdbccrud.api.dto.relations.Ref)2 WithId (io.syndesis.common.model.WithId)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1