Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/main/java/edu/apu/pssdk/CiRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,29 +256,24 @@ public ProxyHashMap toProxyHashMap() throws JOAException {
* @throws JOAException if population fails
*/
public void populateWith(Map<String, Object> dataObject) throws JOAException {
for (Map.Entry<String, Object> incoming : dataObject.entrySet()) {
for (PropertyInfo pi : propInfoCol) {
if (!dataObject.containsKey(pi.getName())) continue;

PropertyInfo pi = propInfoCol.get(incoming.getKey());
Object incomingVal = incoming.getValue();
// if it's read only, we can not do anything about it and PS is going to complain if we try
if (incomingVal == null || pi == null || pi.isReadOnly()) continue;
Object incomingVal = dataObject.get(pi.getName());
if (incomingVal == null || pi.isReadOnly()) continue;

String propName = pi.getName();

// check if the property is a Scroll
if (pi.isCollection()) {
Object exVal = get(propName);

if (!Is.polyglotList(incomingVal))
if (!Is.polyglotList(incomingVal) && !Is.listOfMaps(incomingVal))
throw new JOAException(propName + " should be an Array of CIRows.");

Object exVal = get(propName);
CiScroll scroll = CiScroll.factory(exVal, pi.getPropertyInfoCollection());
@SuppressWarnings("unchecked")
List<Map<String, Object>> subDataList = (List<Map<String, Object>>) incomingVal;

scroll.populateWith(subDataList);
} else {
// if the property is not Read-Only and is not a CIScroll
set(propName, incomingVal);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/edu/apu/pssdk/Is.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package edu.apu.pssdk;

import java.util.List;
import java.util.Map;

/** Utility class with static methods to check object types. */
public class Is {

Expand Down Expand Up @@ -35,4 +38,14 @@ public static boolean polyglotList(Object obj) {
String className = "class com.oracle.truffle.polyglot.PolyglotList";
return obj.getClass().toString().equals(className);
}

public static boolean listOfMaps(Object obj) {
try {
@SuppressWarnings("unchecked")
List<Map<String, Object>> list = (List<Map<String, Object>>) obj;
return list.stream().allMatch(item -> item instanceof Map);
} catch (ClassCastException e) {
return false;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/edu/apu/pssdk/PropertyInfoCollection.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package edu.apu.pssdk;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
Expand All @@ -16,7 +16,7 @@
*/
public class PropertyInfoCollection implements Iterable<PropertyInfo> {

Map<String, PropertyInfo> mapPropInfo = new HashMap<String, PropertyInfo>();
Map<String, PropertyInfo> mapPropInfo = new LinkedHashMap<String, PropertyInfo>();
Logger logger;

/**
Expand Down