Package org.activiti.engine.repository

Examples of org.activiti.engine.repository.Model


  }
 
  @Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testUpdateModel() throws Exception {
   
    Model model = null;
    try {
      Calendar createTime = Calendar.getInstance();
      createTime.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());
     
      model = repositoryService.newModel();
      model.setCategory("Model category");
      model.setKey("Model key");
      model.setMetaInfo("Model metainfo");
      model.setName("Model name");
      model.setVersion(2);
      repositoryService.saveModel(model);
     
     
      Calendar updateTime = Calendar.getInstance();
      updateTime.set(Calendar.MILLISECOND, 0);
      updateTime.add(Calendar.HOUR, 1);
      processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());
     
      // Create update request
      ObjectNode requestNode = objectMapper.createObjectNode();
      requestNode.put("name", "Updated name");
      requestNode.put("category", "Updated category");
      requestNode.put("key", "Updated key");
      requestNode.put("metaInfo", "Updated metainfo");
      requestNode.put("deploymentId", deploymentId);
      requestNode.put("version", 3);
      requestNode.put("tenantId", "myTenant");
     
      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
      httpPut.setEntity(new StringEntity(requestNode.toString()));
      CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
     
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertNotNull(responseNode);
      assertEquals("Updated name", responseNode.get("name").textValue());
      assertEquals("Updated key", responseNode.get("key").textValue());
      assertEquals("Updated category", responseNode.get("category").textValue());
      assertEquals(3, responseNode.get("version").intValue());
      assertEquals("Updated metainfo", responseNode.get("metaInfo").textValue());
      assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
      assertEquals(model.getId(), responseNode.get("id").textValue());
      assertEquals("myTenant", responseNode.get("tenantId").textValue());
     
      assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
      assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
     
      assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
      assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
     
    } finally
    {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here


    }
  }
 
  @Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testUpdateModelOverrideWithNull() throws Exception {
    Model model = null;
    try {
      Calendar createTime = Calendar.getInstance();
      createTime.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());

      model = repositoryService.newModel();
      model.setCategory("Model category");
      model.setKey("Model key");
      model.setMetaInfo("Model metainfo");
      model.setName("Model name");
      model.setTenantId("myTenant");
      model.setVersion(2);
      repositoryService.saveModel(model);
     
      Calendar updateTime = Calendar.getInstance();
      updateTime.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());
     
      // Create update request
      ObjectNode requestNode = objectMapper.createObjectNode();
      requestNode.put("name", (String) null);
      requestNode.put("category", (String) null);
      requestNode.put("key", (String) null);
      requestNode.put("metaInfo", (String) null);
      requestNode.put("deploymentId", (String) null);
      requestNode.put("version", (String) null);
      requestNode.put("tenantId", (String) null);
     
      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
      httpPut.setEntity(new StringEntity(requestNode.toString()));
      CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertNotNull(responseNode);
      assertNull(responseNode.get("name").textValue());
      assertNull(responseNode.get("key").textValue());
      assertNull(responseNode.get("category").textValue());
      assertNull(responseNode.get("version").textValue());
      assertNull(responseNode.get("metaInfo").textValue());
      assertNull(responseNode.get("deploymentId").textValue());
      assertNull(responseNode.get("tenantId").textValue());
      assertEquals(model.getId(), responseNode.get("id").textValue());
     
      assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
      assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
     
      assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
     
      model = repositoryService.getModel(model.getId());
      assertNull(model.getName());
      assertNull(model.getKey());
      assertNull(model.getCategory());
      assertNull(model.getMetaInfo());
      assertNull(model.getDeploymentId());
      assertEquals("", model.getTenantId());
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

*/
public class ModelResourceSourceTest extends BaseSpringRestTestCase {

  public void testGetModelEditorSource() throws Exception {
   
    Model model = null;
    try {
     
      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);
     
      repositoryService.addModelEditorSource(model.getId(), "This is the editor source".getBytes());
     
      HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
      CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
     
      // Check "OK" status
      assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
      assertEquals("This is the editor source", IOUtils.toString(response.getEntity().getContent()));
      closeResponse(response);
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

      }
    }
  }
 
  public void testGetModelEditorSourceNoSource() throws Exception {
    Model model = null;
    try {
     
      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);
     
      HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
      closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

    }
  }
 
  public void testGetModelEditorSourceExtra() throws Exception {
   
    Model model = null;
    try {
     
      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);
     
      repositoryService.addModelEditorSourceExtra(model.getId(), "This is the extra editor source".getBytes());
     
      HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
      CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
     
      // Check "OK" status
      assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
      assertEquals("This is the extra editor source", IOUtils.toString(response.getEntity().getContent()));
      closeResponse(response);
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

      }
    }
  }
 
  public void testGetModelEditorSourceExtraNoSource() throws Exception {
    Model model = null;
    try {
     
      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);
     
      HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
      closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

    return editorSource;
  }

  @RequestMapping(value="/repository/models/{modelId}/source-extra", method = RequestMethod.PUT)
  protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    if (model != null) {
      try {
       
        if (request instanceof MultipartHttpServletRequest == false) {
          throw new ActivitiIllegalArgumentException("Multipart request is required");
        }
       
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
       
        if (multipartRequest.getFileMap().size() == 0) {
          throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
        }
       
        MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
       
        repositoryService.addModelEditorSourceExtra(model.getId(), file.getBytes());
        response.setStatus(HttpStatus.NO_CONTENT.value());
       
      } catch (Exception e) {
        throw new ActivitiException("Error adding model editor source extra", e);
      }
View Full Code Here

@RestController
public class ModelResource extends BaseModelResource {

  @RequestMapping(value="/repository/models/{modelId}", method = RequestMethod.GET, produces = "application/json")
  public ModelResponse getModel(@PathVariable String modelId, HttpServletRequest request) {
    Model model = getModelFromRequest(modelId);
   
    String serverRootUrl = request.getRequestURL().toString();
    serverRootUrl = serverRootUrl.substring(0, serverRootUrl.indexOf("/repository/models/"));
    return restResponseFactory.createModelResponse(model, serverRootUrl);
  }
View Full Code Here

    return restResponseFactory.createModelResponse(model, serverRootUrl);
  }
 
  @RequestMapping(value="/repository/models/{modelId}", method = RequestMethod.PUT, produces = "application/json")
  public ModelResponse updateModel(@PathVariable String modelId, @RequestBody ModelRequest modelRequest, HttpServletRequest request) {
    Model model = getModelFromRequest(modelId);
   
    if (modelRequest.isCategoryChanged()) {
      model.setCategory(modelRequest.getCategory());
    }
    if (modelRequest.isDeploymentChanged()) {
      model.setDeploymentId(modelRequest.getDeploymentId());
    }
    if (modelRequest.isKeyChanged()) {
      model.setKey(modelRequest.getKey());
    }
    if (modelRequest.isMetaInfoChanged()) {
      model.setMetaInfo(modelRequest.getMetaInfo());
    }
    if (modelRequest.isNameChanged()) {
      model.setName(modelRequest.getName());
    }
    if (modelRequest.isVersionChanged()) {
      model.setVersion(modelRequest.getVersion());
    }
    if (modelRequest.isTenantIdChanged()) {
      model.setTenantId(modelRequest.getTenantId());
    }
   
    repositoryService.saveModel(model);
    String serverRootUrl = request.getRequestURL().toString();
    serverRootUrl = serverRootUrl.substring(0, serverRootUrl.indexOf("/repository/models/"));
View Full Code Here

    return restResponseFactory.createModelResponse(model, serverRootUrl);
  }

  @RequestMapping(value="/repository/models/{modelId}", method = RequestMethod.DELETE)
  public void deleteModel(@PathVariable String modelId, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    repositoryService.deleteModel(model.getId());
    response.setStatus(HttpStatus.NO_CONTENT.value());
  }
View Full Code Here

TOP

Related Classes of org.activiti.engine.repository.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.