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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations