1 21 package com.jaspersoft.jasperserver.war.action; 22 23 import org.springframework.webflow.action.FormAction; 24 import org.springframework.webflow.RequestContext; 25 import org.springframework.webflow.ScopeType; 26 import org.springframework.webflow.Event; 27 import org.springframework.webflow.AttributeMap; 28 import org.springframework.validation.DataBinder; 29 import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor; 30 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService; 31 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder; 32 import com.jaspersoft.jasperserver.api.metadata.common.domain.DataType; 33 import com.jaspersoft.jasperserver.api.metadata.common.domain.client.FolderImpl; 34 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl; 35 import com.jaspersoft.jasperserver.war.validation.FolderValidator; 36 import com.jaspersoft.jasperserver.war.validation.DataTypeValidator; 37 import com.jaspersoft.jasperserver.war.dto.DataTypeWrapper; 38 import com.jaspersoft.jasperserver.war.dto.BaseDTO; 39 40 44 public class EditDataTypeAction extends FormAction 45 { 46 private static final String FORM_OBJECT_KEY = "dataType"; 47 private static final String PARENT_FOLDER_ATTR = "parentFolder"; 48 private static final String CURRENT_DATATYPE_ATTR = "currentDataType"; 49 private static final String IS_EDIT = "isEdit"; 51 52 private RepositoryService repository; 53 54 public RepositoryService getRepository() { 55 return repository; 56 } 57 58 public void setRepository(RepositoryService repository) { 59 this.repository = repository; 60 } 61 62 63 protected void initBinder(RequestContext context, DataBinder binder) { 64 binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); 65 } 66 67 68 71 public EditDataTypeAction(){ 72 setFormObjectClass(DataTypeWrapper.class); setFormObjectName(FORM_OBJECT_KEY); 74 setFormObjectScope(ScopeType.FLOW); setValidator(new DataTypeValidator()); 76 } 77 78 79 82 public Object loadFormObject(RequestContext context) 83 { 84 DataType dataType; 85 DataTypeWrapper wrapper; 86 ExecutionContextImpl executionContext = new ExecutionContextImpl(); 87 88 if (context.getFlowScope().get(IS_EDIT) != null) 89 { 90 String currentDataType = (String ) context.getFlowScope().get(CURRENT_DATATYPE_ATTR); 91 dataType = (DataType) repository.getResource(executionContext, currentDataType); 92 wrapper = new DataTypeWrapper(dataType); 93 wrapper.setMode(BaseDTO.MODE_STAND_ALONE_EDIT); 94 } 95 else 96 { 97 dataType = (DataType) repository.newResource(executionContext, DataType.class); 98 String parentFolder = (String ) context.getFlowScope().get(PARENT_FOLDER_ATTR); 99 if (parentFolder == null || parentFolder.trim().length() == 0) 100 parentFolder = "/"; 101 dataType.setParentFolder(parentFolder); 102 wrapper = new DataTypeWrapper(dataType); 103 wrapper.setMode(BaseDTO.MODE_STAND_ALONE_NEW); 104 } 105 106 return wrapper; 107 } 108 109 110 113 public Event saveDataType(RequestContext context) throws Exception 114 { 115 DataTypeWrapper wrapper = (DataTypeWrapper) getFormObject(context); 116 if (wrapper.isStandAloneMode()) 117 repository.saveResource(null, wrapper.getDataType()); 118 119 return success(); 120 } 121 122 125 public Event setupEditForm(RequestContext context) throws Exception 126 { 127 AttributeMap rs = context.getRequestScope(); 128 rs.put(FORM_OBJECT_KEY, getFormObject(context)); 129 return success(); 130 } 131 132 } 133 134 | Popular Tags |