gt:         JsonArray data = Modal.buildSourceArray("/group", "/user");
context: package org.kramerlab.seitan.api.impl.services;
  
  import org.apache.jena.atlas.json.JsonArray;
  import org.apache.jena.atlas.json.JsonObject;
  import org.kramerlab.seitan.api.impl.Strings;
  import org.kramerlab.seitan.api.impl.exceptions.SEITANException;
  import org.kramerlab.seitan.api.impl.mediation.PackageManagementInterface;
  import org.kramerlab.seitan.api.impl.objects.Package;
  import org.kramerlab.seitan.api.impl.util.Modal;
  import org.kramerlab.seitan.api.impl.util.URITool;
  import org.kramerlab.seitan.api.services.PackageIDService;
  import org.springframework.stereotype.Service;
  
  import javax.servlet.http.HttpServletResponse;
  import javax.ws.rs.Path;
  import javax.ws.rs.core.UriInfo;
  import java.io.IOException;
  import java.net.URI;
  import java.util.HashSet;
  import java.util.Set;
  
  
  /**
   * Service listening to /package/id
   */
  @Service("PackageIDService")
  @Path("package/{id : [a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}")
  public class PackageIDServiceImpl extends
          SeitanServiceImpl<PackageManagementInterface> implements
          PackageIDService {
  
      /**
       * Get a specific package by uri
       * Called with GET on /package/id
       *
       * @param uriInfo contains package uri
       * @param modal   modal-specifier
       * @return package JsonObject
       */
      public String getPackage(UriInfo uriInfo, String modal) {
  
          try {
              URI uri = URITool.getPackageURI(uriInfo.getRequestUri());
              Package pack = this.mediation.getPackage(uri);
              JsonObject jo = new JsonObject();
  
              // If modal is true: only add modals+actionsButton
              if("true".equals(modal)){
                  JsonArray modalsArray = new JsonArray();
                  JsonArray actionsButton = new JsonArray();
  
                  for (Modal m : getModals(pack)) {
                      modalsArray.add(m.buildJson());
                      actionsButton.add(m.getActionButton());
                  }
                  jo.put(Strings.MODALS, modalsArray);
                  jo.put(Strings.ACTIONSBUTTON, actionsButton);
                  return jo.toString();
              }
  
              jo.put(Strings.DATA, pack.toJson());
              jo.put(Strings.DATATYPE, "Package");
              jo.put(Strings.ISLIST, Strings.FALSESTRING);
              jo.put(Strings.DESCRIPTION, "Package");
  
              return jo.toString();
          } catch (SEITANException e) {
              e.printStackTrace();
          }
          return null;
      }
  
      /**
       * Updates a specific package with the given data
       * Called with POST on /package/id
       * @param uriInfo contains package uri
       * @param newName new name
       * @param newDescription new description
       * @param newPrimaryGroup new primary group
       * @param newReader new reader
       * @param newWriter new writer
       * @param rmReader reader which is to be removed
       * @param rmWriter writer which is to be remvoed
       * @param newOwner new owner
       */
      public void updatePackage(UriInfo uriInfo, String newName,
                                String newDescription, String newPrimaryGroup,
                                String newReader, String newWriter,
                                String rmReader, String rmWriter,
                                String newOwner, String isDelete) {
          // Catch delete
          if("true".equals(isDelete)){
              this.deletePackage(uriInfo);
              return;
          }
  
          try {
              // Get package
              URI uri = URITool.getPackageURI(uriInfo.getRequestUri());
              Package p = this.mediation.getPackage(uri);
  
              // Update package
              boolean hasChanged =this.mediation.updatePackage(uriInfo, newName, newDescription,
                      newPrimaryGroup, newReader, newWriter, rmReader, rmWriter,
                      newOwner);
  
              // Redirect
              HttpServletResponse res = this.ctx.getHttpServletResponse();
              if (hasChanged) {
                  res.sendRedirect(p.getUri().toString());
              } else {
                  res.sendRedirect(p.getUri().toString() + "?nothingChanged");
              }
  
  
          } catch (SEITANException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
  
      }
  
      /**
       * Deletes a specific package
       * Called with DELETE on /package/id
       * @param uriInfo contains package uri
       */
      public void deletePackage(UriInfo uriInfo) {
          try {
              URI uri = URITool.getPackageURI(uriInfo.getRequestUri());
              Package p = this.mediation.getPackage(uri);
  
              // Actual deletion
              this.mediation.deletePackage(p.getUri());
  
              // Redirect
              HttpServletResponse res = this.ctx.getHttpServletResponse();
              res.sendRedirect("/package?dr=true");
  
          } catch (SEITANException e) {
              e.printStackTrace();
          } catch (IOException e) {
              // sendRedirect failed
              e.printStackTrace();
          }
      }
  
  
      /**
       * Initializes PackageManagementInterface
       * @param username caller
       * @param request request
       * @return mediation
       * @throws org.kramerlab.seitan.api.impl.exceptions.SEITANException Something went wrong
       */
      @Override
      protected PackageManagementInterface intitializeMediation(String username,
                                                                URI request)
              throws org.kramerlab.seitan.api.impl.exceptions.SEITANException {
          return new PackageManagementInterface(username, request);
      }
  
      /**
       * Creates the modals for the given package
       * @param pack given package
       * @return Set of modals
       * @throws SEITANException Something went wrong
       */
      private Set<Modal> getModals(Package pack) throws SEITANException {
          /* Build delete-Modal */
          Set<Modal> modalsArray = new HashSet<>();
  
          /* Build update-Modal */
          Modal updateModal = new Modal();
          updateModal.setId("updateModal");
          updateModal.setName("Update package");
          updateModal.setDescription("You can update the following content");
          updateModal.isFileUpload(false);
  
          updateModal.addForm("Description", "description", pack
                  .getDescription());
          updateModal.addForm("Name", "name", pack.getName());
  
          updateModal.setActionButton("Update", "glyphicon glyphicon-edit");
  
          modalsArray.add(updateModal);
  
  
          /* Build delete-Modal */
  
          Modal deleteModal = new Modal();
          deleteModal.setId("deleteModal");
          deleteModal.setName("Delete package");
          deleteModal.setDescription("Please confirm to delete this package");
          deleteModal.setActionButton("Delete", "glyphicon glyphicon-trash");
          deleteModal.addHiddenForm(Strings.ISDELETE, Strings.TRUESTRING);
          modalsArray.add(deleteModal);
  
          /* Build permissions Modal */
  
          Modal permModal = new Modal();
          permModal.setId("permModal");
          permModal.setName("Permissions");
          permModal.setDescription("Change the following permissions");
  
  