Search in sources :

Example 1 with FormData

use of com.plumdo.form.entity.FormData in project plumdo-work by wengwh.

the class FormInstanceCollectionResource method createFormInstance.

@ApiOperation(value = "创建表单模型", notes = "根据传过来的modelRequest信息来创建表单模型")
@ApiImplicitParam(name = "modelRequest", value = "表单模型请求实体modelRequest", required = true, dataType = "FormInstanceRequest")
@RequestMapping(value = "/form-instances", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public FormInstanceResponse createFormInstance(@RequestBody FormInstanceRequest formInstanceRequest) {
    FormInstance formInstance = new FormInstance();
    if (formInstanceRequest.getBusinessKey() != null) {
        formInstance.setBusinessKey(formInstanceRequest.getBusinessKey());
    }
    if (formInstanceRequest.getTenantId() != null) {
        formInstance.setTenantId(formInstanceRequest.getTenantId());
    }
    if (formInstanceRequest.getFormDatas() != null) {
        for (FormInstanceData formInstanceData : formInstanceRequest.getFormDatas()) {
            FormData formData = new FormData();
            formData.setFormInstance(formInstance);
            formData.setKey(formInstanceData.getKey());
            formData.setValue(formInstanceData.getValue());
            formInstance.addFormData(formData);
        }
    }
    formInstanceRepository.save(formInstance);
    return responseFactory.createFormInstanceResponse(formInstance);
}
Also used : FormData(com.plumdo.form.entity.FormData) FormInstance(com.plumdo.form.entity.FormInstance) FormInstanceData(com.plumdo.form.rest.instance.FormInstanceData) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with FormData

use of com.plumdo.form.entity.FormData in project plumdo-work by wengwh.

the class FormInstanceResource method updateFormInstance.

@ApiOperation(value = "创建表单模型", notes = "根据传过来的modelRequest信息来创建表单模型")
@ApiImplicitParam(name = "modelRequest", value = "表单模型请求实体modelRequest", required = true, dataType = "FormInstanceRequest")
@RequestMapping(value = "/form-instances/{id}", method = RequestMethod.PUT, produces = "application/json")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public FormInstanceResponse updateFormInstance(@PathVariable Long id, @RequestBody FormInstanceRequest formInstanceRequest) {
    FormInstance formInstance = getFormInstanceFromRequest(id);
    if (formInstanceRequest.getBusinessKey() != null) {
        formInstance.setBusinessKey(formInstanceRequest.getBusinessKey());
    }
    if (formInstanceRequest.getTenantId() != null) {
        formInstance.setTenantId(formInstanceRequest.getTenantId());
    }
    if (formInstanceRequest.getFormDatas() != null) {
        for (FormInstanceData formInstanceData : formInstanceRequest.getFormDatas()) {
            Criteria<FormData> criteria = new Criteria<FormData>();
            criteria.add(Restrictions.eq("key", formInstanceData.getKey(), false));
            criteria.add(Restrictions.eq("formInstance.id", id, false));
            FormData oldFormData = formDataRepository.findOne(criteria);
            if (oldFormData == null) {
                FormData formData = new FormData();
                formData.setFormInstance(formInstance);
                formData.setKey(formInstanceData.getKey());
                formData.setValue(formInstanceData.getValue());
                formInstance.addFormData(formData);
            } else {
                oldFormData.setValue(formInstanceData.getValue());
                formInstance.addFormData(oldFormData);
            }
        }
    }
    formInstanceRepository.save(formInstance);
    return responseFactory.createFormInstanceResponse(formInstance);
}
Also used : FormData(com.plumdo.form.entity.FormData) Criteria(com.plumdo.form.jpa.Criteria) FormInstance(com.plumdo.form.entity.FormInstance) FormInstanceData(com.plumdo.form.rest.instance.FormInstanceData) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with FormData

use of com.plumdo.form.entity.FormData in project plumdo-work by wengwh.

the class ResponseFactory method createFormInstanceResponse.

public FormInstanceResponse createFormInstanceResponse(FormInstance formInstance) {
    FormInstanceResponse response = new FormInstanceResponse();
    response.setBaseEntity(formInstance);
    response.setBusinessKey(formInstance.getBusinessKey());
    for (FormData formData : formInstance.getFormDatas()) {
        response.addFormData(formData);
    }
    return response;
}
Also used : FormData(com.plumdo.form.entity.FormData) FormInstanceResponse(com.plumdo.form.rest.instance.FormInstanceResponse)

Example 4 with FormData

use of com.plumdo.form.entity.FormData in project plumdo-work by wengwh.

the class FormDataResource method deleteFormData.

@ApiOperation(value = "删除表单内容", notes = "根据表单内容的id来删除指定对象")
@ApiImplicitParam(name = "id", value = "表单内容ID", required = true, dataType = "Long", paramType = "path")
@RequestMapping(value = "/form-datas/{id}", method = RequestMethod.DELETE, name = "模型删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteFormData(@PathVariable Long id) {
    FormData formData = getFormDataFromRequest(id);
    formDataRepository.delete(formData);
}
Also used : FormData(com.plumdo.form.entity.FormData) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FormData (com.plumdo.form.entity.FormData)4 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 FormInstance (com.plumdo.form.entity.FormInstance)2 FormInstanceData (com.plumdo.form.rest.instance.FormInstanceData)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Criteria (com.plumdo.form.jpa.Criteria)1 FormInstanceResponse (com.plumdo.form.rest.instance.FormInstanceResponse)1