All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hframe.service.handler.HfpmModuleHandler Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.hframe.service.handler;

import com.hframe.domain.model.HfpmModule;
import com.hframe.domain.model.HfpmProgram;
import com.hframe.service.interfaces.IHfpmModuleSV;
import com.hframe.service.interfaces.IHfpmProgramSV;
import com.hframework.web.extension.AbstractBusinessHandler;
import com.hframework.web.extension.annotation.AfterCreateHandler;
import com.hframework.web.extension.annotation.AfterDeleteHandler;
import com.hframework.common.util.file.FileUtils;
import com.hframework.common.util.message.XmlUtils;
import com.hframework.generator.util.CreatorUtil;
import com.hframework.web.config.bean.Program;
import com.hframework.web.config.bean.program.Module;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhangquanhong on 2016/10/14.
 */
@Service
public class HfpmModuleHandler extends AbstractBusinessHandler {
    @Resource
    private IHfpmProgramSV hfpmProgramSV;

    @Resource
    private IHfpmModuleSV hfpmModuleSV;


    @AfterCreateHandler
    public boolean createModule(HfpmModule module) throws Exception {
        String companyCode = "hframework";
        HfpmProgram hfpmProgram = hfpmProgramSV.getHfpmProgramByPK(module.getHfpmProgramId());
        String programCode = hfpmProgram.getHfpmProgramCode();
        String projectBasePath = CreatorUtil.getTargetProjectBasePath(companyCode,
                programCode, null);


        Program program = XmlUtils.readValueFromAbsoluteFilePath(projectBasePath + "/basic/src/main/resources/program/program.xml", Program.class);

        List moduleList = program.getModules().getModuleList();
        if(moduleList == null) {
            moduleList = new ArrayList();
            program.getModules().setModuleList(moduleList);
        }

        for (Module module1 : moduleList) {
            if(module1.getCode().equals(module.getHfpmModuleCode())) {
                return true;
            }
        }

        com.hframework.web.config.bean.program.Module module1 = new com.hframework.web.config.bean.program.Module();
        module1.setCode(module.getHfpmModuleCode());
        module1.setName(module.getHfpmModuleName());
        moduleList.add(module1);

        String xml = XmlUtils.writeValueAsString(program);
        FileUtils.writeFile(projectBasePath + "/basic/src/main/resources/program/program.xml", xml);

        return true;
    }


    @AfterDeleteHandler
    public boolean deleteModule(HfpmModule module) throws Exception {
        String companyCode = "hframework";
        HfpmProgram hfpmProgram = hfpmProgramSV.getHfpmProgramByPK(module.getHfpmProgramId());
        String programCode = hfpmProgram.getHfpmProgramCode();
        String projectBasePath = CreatorUtil.getTargetProjectBasePath(companyCode,
                programCode, null);


        Program program = XmlUtils.readValueFromAbsoluteFilePath(projectBasePath + "/basic/src/main/resources/program/program.xml", Program.class);

        List moduleList = program.getModules().getModuleList();
        if(moduleList == null) {
            moduleList = new ArrayList();
            program.getModules().setModuleList(moduleList);
        }
        Iterator iterator = moduleList.iterator();
        while (iterator.hasNext()) {
            Module module1 = iterator.next();
            if(module1.getCode().equals(module.getHfpmModuleCode())) {
                iterator.remove();
            }
        }

        String xml = XmlUtils.writeValueAsString(program);
        FileUtils.writeFile(projectBasePath + "/basic/src/main/resources/program/program.xml", xml);

        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy