Search in sources :

Example 81 with Entity

use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        Serializable instance = dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        if (instance instanceof Status) {
            ((Status) instance).setArchived('Y');
            dynamicEntityDao.merge(instance);
            return;
        }
    } catch (Exception ex) {
        throw new ServiceException("Unable to perform remove for entity: " + entity.getType()[0], ex);
    }
    super.remove(persistencePackage, dynamicEntityDao, helper);
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) IndexField(org.broadleafcommerce.core.search.domain.IndexField) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 82 with Entity

use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        IndexField adminInstance = (IndexField) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
        return getEntity(persistencePackage, dynamicEntityDao, helper, entity, adminProperties, adminInstance);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform add for entity: " + IndexField.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IndexField(org.broadleafcommerce.core.search.domain.IndexField) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 83 with Entity

use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.

the class AdminProductController method constructSelectizeOptionMap.

public Map<String, Object> constructSelectizeOptionMap(DynamicResultSet drs, ClassMetadata cmd) {
    Map<String, Object> result = new HashMap<>();
    List<Map<String, String>> options = new ArrayList<>();
    for (Entity e : drs.getRecords()) {
        Map<String, String> selectizeOption = new HashMap<>();
        Property p = e.findProperty("MAIN_ENTITY_NAME");
        if (p != null) {
            selectizeOption.put("name", p.getValue());
            selectizeOption.put("id", p.getValue());
        }
        if (e.findProperty(ALTERNATE_ID_PROPERTY) != null) {
            selectizeOption.put("alternateId", e.findProperty(ALTERNATE_ID_PROPERTY).getValue());
        }
        options.add(selectizeOption);
    }
    result.put("options", options);
    return result;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 84 with Entity

use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.

the class FormBuilderServiceImpl method constructSelectizeOptionMap.

@Override
public Map<String, Object> constructSelectizeOptionMap(DynamicResultSet drs, ClassMetadata cmd) {
    Map<String, Object> result = new HashMap<>();
    List<Map<String, String>> options = new ArrayList<>();
    List<Field> headerFields = new ArrayList<>();
    for (Property p : cmd.getProperties()) {
        if (p.getMetadata() instanceof BasicFieldMetadata) {
            BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
            if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
                Field hf = createHeaderField(p, md);
                headerFields.add(hf);
            }
        }
    }
    for (Entity e : drs.getRecords()) {
        Map<String, String> selectizeOption = new HashMap<>();
        for (Field headerField : headerFields) {
            Property p = e.findProperty(headerField.getName());
            if (p != null) {
                selectizeOption.put("name", p.getValue());
                break;
            }
        }
        if (e.findProperty("id") != null) {
            selectizeOption.put("id", e.findProperty("id").getValue());
        }
        if (e.findProperty(ALTERNATE_ID_PROPERTY) != null) {
            selectizeOption.put("alternateId", e.findProperty(ALTERNATE_ID_PROPERTY).getValue());
        }
        options.add(selectizeOption);
    }
    result.put("options", options);
    return result;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 85 with Entity

use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method createRuleData.

public DataWrapper createRuleData(Entity[] entities, String mvelProperty, String quantityProperty, String idProperty, String containedProperty, RuleBuilderFieldService fieldService) {
    if (entities == null || entities.length == 0 || mvelProperty == null) {
        return null;
    }
    DataWrapper dataWrapper = new DataWrapper();
    String mvel = null;
    try {
        for (Entity e : entities) {
            Integer qty = null;
            Long id = null;
            Long containedId = null;
            for (Property p : e.getProperties()) {
                if (mvelProperty.equals(p.getName())) {
                    mvel = p.getValue();
                }
                if (quantityProperty != null && quantityProperty.equals(p.getName())) {
                    qty = Integer.parseInt(p.getValue());
                }
                if (idProperty != null && idProperty.equals(p.getName())) {
                    id = Long.parseLong(p.getValue());
                }
                if (containedProperty != null && containedProperty.equals(p.getName())) {
                    containedId = Long.parseLong(p.getValue());
                }
            }
            if (mvel != null) {
                Group group = groupingTranslator.createGroups(mvel);
                DataDTO dataDTO = createRuleDataDTO(null, group, fieldService);
                if (dataDTO != null) {
                    dataDTO.setPk(id);
                    dataDTO.setContainedPk(containedId);
                    dataDTO.setQuantity(qty);
                    dataWrapper.getData().add(dataDTO);
                    if (group.getSubGroups().size() > 0) {
                        Boolean invalidSubGroupFound = checkForInvalidSubGroup(dataDTO);
                        if (invalidSubGroupFound) {
                            throw new MVELTranslationException(MVELTranslationException.SUB_GROUP_DETECTED, SUB_GROUP_MESSAGE);
                        }
                    }
                }
            }
        }
    } catch (MVELTranslationException e) {
        LOG.error("Unable to translate rule MVEL", e);
        dataWrapper.getData().clear();
        dataWrapper.setError(e.getLocalizedMessage());
        dataWrapper.setRawMvel(mvel);
    }
    return dataWrapper;
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) Group(org.broadleafcommerce.openadmin.web.rulebuilder.grouping.Group) DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

Entity (org.broadleafcommerce.openadmin.dto.Entity)112 Property (org.broadleafcommerce.openadmin.dto.Property)62 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)51 ServiceException (org.broadleafcommerce.common.exception.ServiceException)48 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)36 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)34 ArrayList (java.util.ArrayList)25 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)24 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)24 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)20 Serializable (java.io.Serializable)19 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)19 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)17 Map (java.util.Map)16 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)16 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)16 HashMap (java.util.HashMap)15 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14