Search in sources :

Example 46 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method removeEntity.

/**
 * Attempts to remove the given entity.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/delete", method = RequestMethod.POST)
public String removeEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(sectionClassName, getSectionCustomCriteria());
    Entity entity = service.removeEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
    // Removal does not normally return an Entity unless there is some validation error
    if (entity != null) {
        entityFormValidator.validate(entityForm, entity, result);
        if (result.hasErrors()) {
            // Create a flash attribute for the unsuccessful delete
            FlashMap fm = new FlashMap();
            fm.put("headerFlash", "delete.unsuccessful");
            fm.put("headerFlashAlert", true);
            request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, fm);
            // Re-look back up the entity so that we can return something populated
            PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
            ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
            entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
            Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForAllSubCollections(ppr, entity, sectionCrumbs);
            entityForm.clearFieldsMap();
            formService.populateEntityForm(cmd, entity, subRecordsMap, entityForm, sectionCrumbs);
            modifyEntityForm(entityForm, pathVars);
            return populateJsonValidationErrors(entityForm, result, new JsonResponse(response)).done();
        }
    }
    ra.addFlashAttribute("headerFlash", "delete.successful");
    ra.addFlashAttribute("headerFlashAlert", true);
    if (isAjaxRequest(request)) {
        // redirect attributes won't work here since ajaxredirect actually makes a new request
        return "ajaxredirect:" + getContextPath(request) + sectionKey + "?headerFlash=delete.successful";
    } else {
        return "redirect:/" + sectionKey;
    }
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FlashMap(org.springframework.web.servlet.FlashMap) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) JsonResponse(org.broadleafcommerce.common.web.JsonResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminAbstractController method getSectionPersistencePackageRequest.

/**
 * Returns a PersistencePackageRequest for the given sectionClassName. Will also invoke the
 * {@link #getSectionCustomCriteria()} and {@link #attachSectionSpecificInfo(PersistencePackageRequest)} to allow
 * specialized controllers to manipulate the request for every action in this controller.
 *
 * @param sectionClassName
 * @param sectionCrumbs
 * @param pathVars
 * @return
 */
protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, List<SectionCrumb> sectionCrumbs, Map<String, String> pathVars) {
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(sectionClassName, getSectionCustomCriteria());
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(sectionClassName).withCustomCriteria(sectionCriteria).withSectionCrumbs(sectionCrumbs);
    attachSectionSpecificInfo(ppr, pathVars);
    return ppr;
}
Also used : PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)

Example 48 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminAbstractController method getSectionPersistencePackageRequest.

/**
 * Returns the result of a call to getSectionPersistencePackageRequest(..) with the additional filter
 * and sort criteria attached.
 *
 * @param sectionClassName
 * @param requestParams
 * @param sectionCrumbs
 * @param pathVars
 * @return the PersistencePacakageRequest
 */
protected PersistencePackageRequest getSectionPersistencePackageRequest(String sectionClassName, MultiValueMap<String, String> requestParams, List<SectionCrumb> sectionCrumbs, Map<String, String> pathVars) {
    FilterAndSortCriteria[] fascs = getCriteria(requestParams);
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(sectionClassName, getSectionCustomCriteria());
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(sectionClassName).withCustomCriteria(sectionCriteria).withFilterAndSortCriteria(fascs).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withSectionCrumbs(sectionCrumbs).withLastId(getLastId(requestParams)).withFirstId(getFirstId(requestParams)).withUpperCount(getUpperCount(requestParams)).withLowerCount(getLowerCount(requestParams)).withPageSize(getPageSize(requestParams)).withPresentationFetch(true);
    attachSectionSpecificInfo(ppr, pathVars);
    return ppr;
}
Also used : PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)

Aggregations

PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)48 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)36 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)29 Property (org.broadleafcommerce.openadmin.dto.Property)26 Entity (org.broadleafcommerce.openadmin.dto.Entity)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)20 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)19 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)13 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)12 ArrayList (java.util.ArrayList)10 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)10 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)10 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)9 MapMetadata (org.broadleafcommerce.openadmin.dto.MapMetadata)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)7 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)7 HashMap (java.util.HashMap)6