Search in sources :

Example 1 with EntityNotFoundException

use of org.broadleafcommerce.openadmin.exception.EntityNotFoundException in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method getAdvancedCollectionRecord.

@Override
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) throws ServiceException {
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs);
    ppr.addCustomCriteria(customCriteria);
    FieldMetadata md = collectionProperty.getMetadata();
    String containingEntityId = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
    ppr.setSectionEntityField(collectionProperty.getName());
    PersistenceResponse response;
    if (md instanceof AdornedTargetCollectionMetadata) {
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName() + "Target");
        fasc.setFilterValue(collectionItemId);
        ppr.addFilterAndSortCriteria(fasc);
        if (!StringUtils.isEmpty(alternateId)) {
            fasc = new FilterAndSortCriteria(ppr.getAdornedList().getIdProperty());
            fasc.setFilterValue(alternateId);
            ppr.addFilterAndSortCriteria(fasc);
        }
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        if (ArrayUtils.isEmpty(entities)) {
            throw new EntityNotFoundException();
        }
    } else if (md instanceof MapMetadata) {
        MapMetadata mmd = (MapMetadata) md;
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        for (Entity e : entities) {
            String idProperty = getIdProperty(containingClassMetadata);
            if (mmd.isSimpleValue()) {
                idProperty = "key";
            }
            Property p = e.getPMap().get(idProperty);
            if (p.getValue().equals(collectionItemId)) {
                response.setEntity(e);
                break;
            }
        }
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not an " + "advanced collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
    }
    return response;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) EntityNotFoundException(org.broadleafcommerce.openadmin.exception.EntityNotFoundException) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 2 with EntityNotFoundException

use of org.broadleafcommerce.openadmin.exception.EntityNotFoundException in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method getRecord.

@Override
public PersistenceResponse getRecord(PersistencePackageRequest request, String id, ClassMetadata cmd, boolean isCollectionRequest) throws ServiceException {
    String idProperty = getIdProperty(cmd);
    FilterAndSortCriteria fasc = new FilterAndSortCriteria(idProperty);
    fasc.setFilterValue(id);
    request.addFilterAndSortCriteria(fasc);
    PersistenceResponse response = fetch(request);
    Entity[] entities = response.getDynamicResultSet().getRecords();
    if (ArrayUtils.isEmpty(entities)) {
        throw new EntityNotFoundException();
    }
    return response;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) EntityNotFoundException(org.broadleafcommerce.openadmin.exception.EntityNotFoundException)

Aggregations

AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 FilterAndSortCriteria (org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)2 EntityNotFoundException (org.broadleafcommerce.openadmin.exception.EntityNotFoundException)2 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)2 BLCSystemProperty (org.broadleafcommerce.common.util.BLCSystemProperty)1 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)1 MapMetadata (org.broadleafcommerce.openadmin.dto.MapMetadata)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)1