/** Created by Administrator on 14-2-7. */
public class StudentFamilySaveHandler implements DoHandler {

  private XdoManager xdoManager =
      (XdoManager) ApplicationContextUtil.getApplicationContext().getBean("xdoManagerImpl");
  private BaseManager baseManager =
      (BaseManager) ApplicationContextUtil.getApplicationContext().getBean("baseManagerImpl");

  @Override
  public ModelMap handle(ModelMap modelMap, HttpServletRequest request) throws Exception {

    Family family = new Family();
    String type = "new";

    String id = request.getParameter("id");
    if (id != null && !id.equals("")) {
      type = "edit";
      family = (Family) baseManager.getObject(Family.class.getName(), id);
    }

    Do tempDo = (Do) modelMap.get("tempDo");
    family =
        (Family)
            xdoManager.processSaveOrUpdateTempObject(
                tempDo, family, family.getClass(), request, type);

    baseManager.saveOrUpdate(Family.class.getName(), family);
    modelMap.put("object", family);

    BigStudent bigStudent =
        (BigStudent)
            baseManager.getObject(BigStudent.class.getName(), request.getParameter("bigStudentId"));
    bigStudent.setFamily(family);
    baseManager.saveOrUpdate(BigStudent.class.getName(), bigStudent);

    return modelMap;
  }
}
/** Created by Administrator on 2015/7/21. */
public class MasterWorkFormHandler implements MultipartHandler {

  private AliOssUploadManager aliOssUploadManager =
      (AliOssUploadManager)
          ApplicationContextUtil.getApplicationContext().getBean("aliOssUploadManagerImpl");
  private BaseManager baseManager =
      (BaseManager) ApplicationContextUtil.getApplicationContext().getBean("baseManagerImpl");

  @Override
  public ModelMap handleMultipart(
      Do tempDo, ModelMap modelMap, HttpServletRequest request, MultipartRequest multipartRequest)
      throws Exception {
    String introductionId = request.getParameter("master.id");
    MultipartFile multipartFile = multipartRequest.getFile("picurl");

    XSaveOrUpdate xSaveOrUpdate = new XSaveOrUpdate(tempDo.getName(), request);
    HashMap<String, Object> paramMap = xSaveOrUpdate.getParamMap();
    if (multipartFile.getOriginalFilename() != null
        && !multipartFile.getOriginalFilename().equals("")) {
      String url = "work/" + introductionId + "/" + multipartFile.getOriginalFilename();
      aliOssUploadManager.uploadFile(multipartFile, "tenant", url);
      paramMap.put("pictureUrl", url);
    }
    paramMap.put("master.id", introductionId);
    Object object = baseManager.saveOrUpdate(xSaveOrUpdate);

    // 介绍
    String introductionContent = request.getParameter("productDescription");
    ProductDescription productDescription = new ProductDescription();
    productDescription.setContent(introductionContent);
    Product product = new Product();
    product.setId(((MasterWork) object).getId());
    productDescription.setProduct(product);

    baseManager.saveOrUpdate(ProductDescription.class.getName(), productDescription);

    ((MasterWork) object).setProductDescription(productDescription);

    baseManager.saveOrUpdate(MasterWork.class.getName(), object);

    List<String> tagValueList = new ArrayList<>();

    Enumeration<String> paramEnumeration = request.getParameterNames();

    while (paramEnumeration.hasMoreElements()) {
      String paramKey = paramEnumeration.nextElement();
      if (paramKey.startsWith("tag")) {
        String value = request.getParameter(paramKey);
        tagValueList.add(value);
      }
    }

    if (tagValueList.size() > 0) {
      for (String tagId : tagValueList) {
        ProjectTag projectTag = new ProjectTag();
        projectTag.setId(tagId);
        MasterWorkTag masterWorkTag = new MasterWorkTag();
        masterWorkTag.setProjectTag(projectTag);
        masterWorkTag.setMasterWork((MasterWork) object);
        masterWorkTag.setStatus("1");
        baseManager.saveOrUpdate(MasterWorkTag.class.getName(), masterWorkTag);
      }
    }

    modelMap.put("object", object);
    return modelMap;
  }
}
Exemple #3
0
/**
 * Created by IntelliJ IDEA. User: ming Date: 12-10-30 Time: 上午10:30 To change this template use
 * File | Settings | File Templates.
 */
public class RoleHandler implements DoHandler {

  private BaseManager baseManager =
      (BaseManager) ApplicationContextUtil.getApplicationContext().getBean("baseManagerImpl");
  private XdoManager xdoManager =
      (XdoManager) ApplicationContextUtil.getApplicationContext().getBean("xdoManagerImpl");
  private XdoDao xdoDao =
      (XdoDao) ApplicationContextUtil.getApplicationContext().getBean("xdoDaoSupport");

  @Override
  public ModelMap handle(ModelMap modelMap, HttpServletRequest request) throws Exception {

    Role role = new Role();
    String type = "new";

    String id = request.getParameter("id");
    if (id != null && !id.equals("")) {
      type = "edit";
      role = (Role) baseManager.getObject(Role.class.getName(), id);
      if (role.getPermissionsList() != null && role.getPermissionsList().size() > 0) {
        String[] deletePermissionIdArray = new String[role.getPermissionsList().size()];
        for (int i = 0; i < role.getPermissionsList().size(); i++) {
          deletePermissionIdArray[i] = role.getPermissionsList().get(i).getId();
        }
        baseManager.batchDelete(Permission.class.getName(), deletePermissionIdArray);
      }
    }
    Do tempDo = (Do) modelMap.get("tempDo");
    role =
        (Role)
            XDoUtil.processSaveOrUpdateTempObject(
                tempDo, role, role.getClass(), request, type, xdoDao);

    // 建立新的权限
    List<Permission> permissionList = new ArrayList<>();
    String[] entityNames = request.getParameterValues("entityName");
    String[] entityLabels = request.getParameterValues("entityLabel");
    for (int i = 0; i < entityNames.length; i++) {
      Permission permission = new Permission();
      permission.setRole(role);
      String entityName = entityNames[i];
      permission.setEntityName(entityName);
      permission.setEntityLabel(entityLabels[i]);
      if (request.getParameter(entityName + "_all") != null) {
        permission.setAll(true);
        permission.setBasic("all");
        permissionList.add(permission);
      } else {
        permission.setAll(false);
        String[] basicArray = request.getParameterValues(entityName + "_basic");
        if (basicArray != null) {
          StringBuilder basicBuilder = new StringBuilder();
          for (String basic : basicArray) {
            basicBuilder.append(basic).append(",");
          }
          basicBuilder.deleteCharAt(basicBuilder.length() - 1);
          permission.setBasic(basicBuilder.toString());
        }
        String[] othersArray = request.getParameterValues(entityName + "_others");
        if (othersArray != null) {
          StringBuilder othersBuilder = new StringBuilder();
          for (String others : othersArray) {
            othersBuilder.append(others).append(",");
          }
          othersBuilder.deleteCharAt((othersBuilder.length() - 1));
          permission.setOthers(othersBuilder.toString());
        }
        if (basicArray != null || othersArray != null) {
          permissionList.add(permission);
        }
      }
    }
    role.setPermissionsList(permissionList);
    modelMap.put("object", role);
    return modelMap; // To change body of implemented methods use File | Settings | File Templates.
  }
}