001package org.kuali.ole.describe.controller;
002
003import org.kuali.ole.OLEConstants;
004import org.kuali.ole.describe.service.impl.ExternalDSConfigMaintenanceDocumentServiceImpl;
005import org.kuali.ole.service.OlePatronMaintenanceDocumentServiceImpl;
006import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
007import org.kuali.rice.krad.maintenance.MaintenanceDocument;
008import org.kuali.rice.krad.maintenance.MaintenanceUtils;
009import org.kuali.rice.krad.service.MaintenanceDocumentService;
010import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
011import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
012import org.springframework.stereotype.Controller;
013import org.springframework.validation.BindingResult;
014import org.springframework.web.bind.annotation.ModelAttribute;
015import org.springframework.web.bind.annotation.RequestMapping;
016import org.springframework.web.servlet.ModelAndView;
017
018import javax.servlet.http.HttpServletRequest;
019import javax.servlet.http.HttpServletResponse;
020
021/**
022 * Created with IntelliJ IDEA.
023 * User: PJ7789
024 * Date: 10/12/12
025 * Time: 5:25 PM
026 * To change this template use File | Settings | File Templates.
027 */
028
029@Controller
030@RequestMapping(value = "/externalDataSourceMaintenance")
031public class OleExternalDSConfigMaintenanceDocumentController
032        extends MaintenanceDocumentController {
033    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(
034            OleExternalDSConfigMaintenanceDocumentController.class);
035
036    /**
037     * Use to create a link delete in the lookup result action field which will use to delete patron record..
038     *
039     * @param form
040     * @param result
041     * @param request
042     * @param response
043     * @return ModelAndView
044     * @throws Exception
045     */
046    @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
047    public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
048                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
049        LOG.debug(" Inside maintenanceDelete ");
050        setupMaintenanceForDelete(form, request, OLEConstants.OleExternalDataSourceConfig.DATA_SOURCE_DELETE);
051        return getUIFModelAndView(form);
052    }
053
054    /**
055     * This method populates confirmation to delete the document.
056     *
057     * @param form
058     * @param request
059     * @param maintenanceAction
060     */
061    protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request,
062                                             String maintenanceAction) {
063        LOG.debug(" Inside setupMaintenanceForDelete ");
064        MaintenanceDocument document = form.getDocument();
065        if (document == null) {
066            document = getMaintenanceDocumentService()
067                    .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
068                            maintenanceAction);
069
070            form.setDocument(document);
071            form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
072        }
073
074        form.setMaintenanceAction(maintenanceAction);
075        ExternalDSConfigMaintenanceDocumentServiceImpl dataSourceService
076                = (ExternalDSConfigMaintenanceDocumentServiceImpl) getMaintenanceDocumentService();
077        dataSourceService.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
078        MaintenanceUtils.checkForLockingDocument(document, false);
079    }
080
081    /**
082     * This method returns the instance of OleExternalDataSourceConfigMaintenanceDocumentService
083     *
084     * @return OleExternalDataSourceConfigMaintenanceDocumentService(MaintenanceDocumentService)
085     */
086    @Override
087    protected MaintenanceDocumentService getMaintenanceDocumentService() {
088        return GlobalResourceLoader
089                .getService(OLEConstants.OleExternalDataSourceConfig.DATA_SOURCE_MAINTENANCE_DOC_SERVICE);
090    }
091
092}