io.continual.services.model.impl.json.CommonJsonDbObjectContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of continualModel Show documentation
Show all versions of continualModel Show documentation
Continual's modeling library.
package io.continual.services.model.impl.json;
import java.util.Collection;
import org.json.JSONArray;
import org.json.JSONObject;
import io.continual.iam.access.AccessControlList;
import io.continual.util.data.json.JsonVisitor;
import io.continual.util.data.json.JsonVisitor.ItemRenderer;
import io.continual.util.naming.Path;
public class CommonJsonDbObjectContainer
{
public static final String kContainerType = "objectContainer";
public static CommonDataTransfer createObjectContainer ( Path path, Collection containedPaths )
{
final JSONObject data = new JSONObject ();
data.put ( "objects", JsonVisitor.collectionToArray ( containedPaths, new ItemRenderer ()
{
@Override
public String render ( Path containedPath )
{
return containedPath.toString ().substring ( 1 );
}
} ) );
final JSONObject meta = new JSONObject ()
.put ( CommonModelObjectMetadata.kMeta_AclTag, AccessControlList.createOpenAcl ().asJson () )
.put ( CommonModelObjectMetadata.kMeta_LockedTypes, new JSONArray ().put ( kContainerType ) )
;
final JSONObject topLevel = new JSONObject ()
.put ( CommonDataTransfer.kDataTag, data )
.put ( CommonDataTransfer.kMetaTag, meta )
;
return new CommonDataTransfer ( path, topLevel );
}
}