package jpaoletti.jpm2.web.controller;

import jpaoletti.jpm2.core.PMException;
import jpaoletti.jpm2.core.model.Entity;
import jpaoletti.jpm2.core.model.EntityInstance;
import jpaoletti.jpm2.core.model.IdentifiedObject;
import jpaoletti.jpm2.core.model.Operation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author jpaoletti
 */
@Controller
public class AuditController extends BaseController {

    public static final String OP_ITEM_AUDIT = "itemAudit";
    public static final String OP_GENERAL_AUDIT = "generalAudit";

    @RequestMapping(value = "/jpm/{entity}/{instanceId}/" + OP_ITEM_AUDIT, method = RequestMethod.GET)
    public ModelAndView getItemAudit(@PathVariable Entity entity, @PathVariable String instanceId) throws PMException {
        final Operation operation = entity.getOperation(OP_ITEM_AUDIT);
        final IdentifiedObject iobject = getJpm().getService().get(entity, operation, instanceId);
        final ModelAndView mav = new ModelAndView("jpm-" + OP_ITEM_AUDIT);
        getContext().set(entity, operation);
        getContext().setEntityInstance(new EntityInstance(iobject, entity, operation));
        mav.addObject("audits", getJpm().getAuditService().getItemRecords(entity, instanceId));
        return mav;
    }

    @RequestMapping(value = "/jpm/{entity}/" + OP_GENERAL_AUDIT, method = RequestMethod.GET)
    public ModelAndView getGeneralAudit(@PathVariable Entity entity) throws PMException {
        final Operation operation = entity.getOperation(OP_GENERAL_AUDIT);
        final ModelAndView mav = new ModelAndView("jpm-" + OP_GENERAL_AUDIT);
        getContext().set(entity, operation);
        mav.addObject("audits", getJpm().getAuditService().getGeneralRecords(entity));
        return mav;
    }
}

@@ -1992,11 +1992,701 @@
 v;%0A    %7D
+%0A%0A    @RequestMapping(value = %22/jpm/%7Bowner%7D/%7BownerId%7D/%7Bentity%7D/%22 + OP_GENERAL_AUDIT, method = RequestMethod.GET)%0A    public ModelAndView getGeneralAudit(%0A            @PathVariable Entity owner,%0A            @PathVariable String ownerId,%0A            @PathVariable Entity entity) throws PMException %7B%0A        final Operation operation = entity.getOperation(OP_GENERAL_AUDIT);%0A        final ModelAndView mav = new ModelAndView(%22jpm-%22 + OP_GENERAL_AUDIT);%0A        getContext().set(entity, operation);%0A        mav.addObject(%22audits%22, getJpm().getAuditService().getGeneralRecords(entity));%0A        mav.addObject(%22owner%22, owner);%0A        mav.addObject(%22ownerId%22, ownerId);%0A        return mav;%0A    %7D
 %0A%7D%0A

Fix general audit operation for weaks