Search in sources :

Example 16 with FunctionContext

use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.

the class FunctionResource method callMvcFunction.

/**
 * POST  /functions/mvc/{functionKey} : Execute a mvc function by key (key in entity specification).
 *
 * @param functionKey   the function key to execute
 * @param functionInput function input data context
 * @return ModelAndView object
 */
@Timed
@PostMapping("/functions/mvc/{functionKey:.+}")
@PreAuthorize("hasPermission(null, 'FUNCTION.MVC.CALL')")
public ModelAndView callMvcFunction(@PathVariable("functionKey") String functionKey, @RequestBody Map<String, Object> functionInput) {
    FunctionContext result = functionService.execute(functionKey, functionInput);
    Object data = result.getData().get("modelAndView");
    if (data instanceof ModelAndView) {
        return (ModelAndView) data;
    }
    return null;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) PostMapping(org.springframework.web.bind.annotation.PostMapping) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with FunctionContext

use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.

the class FunctionServiceImpl method toFunctionContext.

private FunctionContext toFunctionContext(String functionKey, IdOrKey idOrKey, Map<String, Object> data) {
    XmEntity xmEntity = (idOrKey != null) ? xmEntityService.findOne(idOrKey) : null;
    FunctionContext functionResult = new FunctionContext();
    // TODO review key & typeKey ...
    functionResult.setKey(functionKey + "-" + UUID.randomUUID().toString());
    functionResult.setTypeKey(functionKey);
    functionResult.setData(data);
    functionResult.setStartDate(Instant.now());
    functionResult.setUpdateDate(functionResult.getStartDate());
    functionResult.setXmEntity(xmEntity);
    return functionResult;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext)

Aggregations

FunctionContext (com.icthh.xm.ms.entity.domain.FunctionContext)17 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Transactional (org.springframework.transaction.annotation.Transactional)6 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)3 Instant (java.time.Instant)2 Timed (com.codahale.metrics.annotation.Timed)1 Attachment (com.icthh.xm.ms.entity.domain.Attachment)1 Calendar (com.icthh.xm.ms.entity.domain.Calendar)1 Comment (com.icthh.xm.ms.entity.domain.Comment)1 Event (com.icthh.xm.ms.entity.domain.Event)1 Location (com.icthh.xm.ms.entity.domain.Location)1 Rating (com.icthh.xm.ms.entity.domain.Rating)1 Tag (com.icthh.xm.ms.entity.domain.Tag)1 Vote (com.icthh.xm.ms.entity.domain.Vote)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1