use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getSectionKey.
// ***********************************************
// HELPER METHODS FOR SECTION-SPECIFIC OVERRIDES *
// ***********************************************
/**
* This method is used to determine the current section key. For this default implementation, the sectionKey is pulled
* from the pathVariable, {sectionKey}, as defined by the request mapping on this controller. To support controller
* inheritance and allow more specialized controllers to delegate some methods to this basic controller, overridden
* implementations of this method could return a hardcoded value instead of reading the map
*
* @param pathVars - the map of all currently bound path variables for this request
* @return the sectionKey for this request
*/
protected String getSectionKey(Map<String, String> pathVars) {
String sectionKey = pathVars.get("sectionKey");
AdminSection typedEntitySection = null;
HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
if (request != null) {
typedEntitySection = (AdminSection) request.getAttribute("typedEntitySection");
}
if (typedEntitySection != null) {
sectionKey = typedEntitySection.getUrl().substring(1);
}
return sectionKey;
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method createListGrid.
/**
* Populate a ListGrid with ListGridRecords.
*
* @param className
* @param headerFields
* @param type
* @param drs
* @param sectionKey
* @param order
* @param idProperty
* @param sectionCrumbs
* @param sortPropery
* @return
*/
protected ListGrid createListGrid(String className, List<Field> headerFields, ListGrid.Type type, DynamicResultSet drs, String sectionKey, Integer order, String idProperty, List<SectionCrumb> sectionCrumbs, String sortPropery) {
// Create the list grid and set some basic attributes
ListGrid listGrid = new ListGrid();
listGrid.setClassName(className);
listGrid.getHeaderFields().addAll(headerFields);
listGrid.setListGridType(type);
listGrid.setSectionCrumbs(sectionCrumbs);
listGrid.setSectionKey(sectionKey);
listGrid.setOrder(order);
listGrid.setIdProperty(idProperty);
listGrid.setStartIndex(drs.getStartIndex());
listGrid.setTotalRecords(drs.getTotalRecords());
listGrid.setPageSize(drs.getPageSize());
String sectionIdentifier = extractSectionIdentifierFromCrumb(sectionCrumbs);
AdminSection section = navigationService.findAdminSectionByClassAndSectionId(className, sectionIdentifier);
if (section != null) {
listGrid.setExternalEntitySectionKey(section.getUrl());
}
// format date list grid cells
SimpleDateFormat formatter = new SimpleDateFormat("MMM d, Y @ hh:mma");
DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
symbols.setAmPmStrings(new String[] { "am", "pm" });
formatter.setDateFormatSymbols(symbols);
// that are used for the header fields.
for (Entity e : drs.getRecords()) {
ListGridRecord record = new ListGridRecord();
record.setListGrid(listGrid);
record.setDirty(e.isDirty());
record.setEntity(e);
if (StringUtils.isNotBlank(sortPropery) && e.findProperty(sortPropery) != null) {
Property sort = e.findProperty(sortPropery);
record.setDisplayOrder(sort.getValue());
}
if (e.findProperty("hasError") != null) {
Boolean hasError = Boolean.parseBoolean(e.findProperty("hasError").getValue());
record.setIsError(hasError);
if (hasError) {
ExtensionResultStatusType messageResultStatus = listGridErrorExtensionManager.getProxy().determineErrorMessageForEntity(e, record);
if (ExtensionResultStatusType.NOT_HANDLED.equals(messageResultStatus)) {
record.setErrorKey("listgrid.record.error");
}
}
}
if (e.findProperty("progressStatus") != null) {
ExtensionResultStatusType messageResultStatus = listGridErrorExtensionManager.getProxy().determineStatusMessageForEntity(e, record);
if (ExtensionResultStatusType.NOT_HANDLED.equals(messageResultStatus)) {
record.setStatus(e.findProperty("progressStatus").getValue());
record.setStatusCssClass("listgrid.record.status");
}
}
if (e.findProperty(idProperty) != null) {
record.setId(e.findProperty(idProperty).getValue());
}
for (Field headerField : headerFields) {
Property p = e.findProperty(headerField.getName());
if (p != null) {
Field recordField = new Field().withName(headerField.getName()).withFriendlyName(headerField.getFriendlyName()).withOrder(p.getMetadata().getOrder());
if (headerField instanceof ComboField) {
recordField.setValue(((ComboField) headerField).getOption(p.getValue()));
recordField.setDisplayValue(p.getDisplayValue());
} else {
if (headerField.getFieldType().equals("DATE")) {
try {
Date date = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").parse(p.getValue());
String newValue = formatter.format(date);
recordField.setValue(newValue);
} catch (Exception ex) {
recordField.setValue(p.getValue());
}
} else {
recordField.setValue(p.getValue());
}
recordField.setDisplayValue(p.getDisplayValue());
}
recordField.setDerived(isDerivedField(headerField, recordField, p));
record.getFields().add(recordField);
}
}
if (e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY) != null) {
Field hiddenField = new Field().withName(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
hiddenField.setValue(e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY).getValue());
record.getHiddenFields().add(hiddenField);
}
if (e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY) != null) {
record.setAltId(e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY).getValue());
}
extensionManager.getProxy().modifyListGridRecord(className, record, e);
listGrid.getRecords().add(record);
}
if (drs.getFirstId() != null) {
listGrid.setFirstId(drs.getFirstId());
}
if (drs.getLastId() != null) {
listGrid.setLastId(drs.getLastId());
}
if (drs.getUpperCount() != null) {
listGrid.setUpperCount(drs.getUpperCount());
}
if (drs.getLowerCount() != null) {
listGrid.setLowerCount(drs.getLowerCount());
}
if (drs.getFetchType() != null) {
listGrid.setFetchType(drs.getFetchType().toString());
}
if (drs.getTotalCountLessThanPageSize() != null) {
listGrid.setTotalCountLessThanPageSize(drs.getTotalCountLessThanPageSize());
}
if (drs.getPromptSearch() != null) {
listGrid.setPromptSearch(drs.getPromptSearch());
}
return listGrid;
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method populateEntityForm.
@Override
public void populateEntityForm(ClassMetadata cmd, EntityForm ef, List<SectionCrumb> sectionCrumbs) throws ServiceException {
ef.setCeilingEntityClassname(cmd.getCeilingType());
String sectionIdentifier = extractSectionIdentifierFromCrumb(sectionCrumbs);
AdminSection section = navigationService.findAdminSectionByClassAndSectionId(cmd.getCeilingType(), sectionIdentifier);
if (section != null) {
ef.setSectionKey(section.getUrl());
} else {
ef.setSectionKey(cmd.getCeilingType());
}
ef.setSectionCrumbsImpl(sectionCrumbs);
setEntityFormTabsAndGroups(ef, cmd.getTabAndGroupMetadata());
setEntityFormFields(cmd, ef, Arrays.asList(cmd.getProperties()));
populateDropdownToOneFields(ef, cmd);
extensionManager.getProxy().modifyUnpopulatedEntityForm(ef);
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method constructFieldDTOFromFieldData.
protected FieldDTO constructFieldDTOFromFieldData(Field field, BasicFieldMetadata fmd) {
FieldDTO fieldDTO = new FieldDTO();
// translate the label to display
String label = field.getFriendlyName();
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
MessageSource messages = context.getMessageSource();
if (messages != null) {
label = messages.getMessage(label, null, label, context.getJavaLocale());
}
fieldDTO.setLabel(label);
fieldDTO.setId(field.getName());
if (field.getFieldType().equals("STRING")) {
fieldDTO.setOperators("blcFilterOperators_Text");
} else if (field.getFieldType().equals("DATE")) {
fieldDTO.setOperators("blcFilterOperators_Date");
} else if (field.getFieldType().equals("NUMBER") || field.getFieldType().equals("MONEY") || field.getFieldType().equals("DECIMAL")) {
fieldDTO.setOperators("blcFilterOperators_Numeric");
} else if (field.getFieldType().equals("BOOLEAN")) {
fieldDTO.setOperators("blcFilterOperators_Boolean");
} else if (field.getFieldType().equals("BROADLEAF_ENUMERATION")) {
fieldDTO.setOperators("blcFilterOperators_Enumeration");
fieldDTO.setInput("select");
fieldDTO.setType("string");
String[][] enumerationValues = fmd.getEnumerationValues();
Map<String, String> enumMap = new HashMap<>();
for (int i = 0; i < enumerationValues.length; i++) {
enumMap.put(enumerationValues[i][0], enumerationValues[i][1]);
}
fieldDTO.setValues(new JSONObject(enumMap).toString());
} else if (field.getFieldType().equals("ADDITIONAL_FOREIGN_KEY")) {
fieldDTO.setOperators("blcFilterOperators_Selectize");
fieldDTO.setType("string");
AdminSection section = adminNavigationService.findAdminSectionByClassAndSectionId(fmd.getForeignKeyClass(), null);
if (section != null) {
String sectionKey = section.getUrl().substring(1);
fieldDTO.setSelectizeSectionKey(sectionKey);
} else {
fieldDTO.setSelectizeSectionKey(fmd.getForeignKeyClass());
}
} else {
fieldDTO.setOperators("blcFilterOperators_Text");
}
return fieldDTO;
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminTypedEntityRequestFilter method isRequestForTypedEntity.
@SuppressWarnings("unchecked")
public boolean isRequestForTypedEntity(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
String servletPath = request.getServletPath();
if (!servletPath.contains(":")) {
return false;
}
// Find the Admin Section for the typed entity.
String sectionKey = getSectionKeyFromRequest(request);
AdminSection typedEntitySection = adminNavigationService.findAdminSectionByURI(sectionKey);
// If the Typed Entity Section does not exist, continue with the filter chain.
if (typedEntitySection == null) {
return false;
}
// Check if the item requested matches the item section
TypedEntity typedEntity = getTypedEntityFromServletPathId(servletPath, typedEntitySection.getCeilingEntity());
if (typedEntity != null && !typeMatchesAdminSection(typedEntity, sectionKey)) {
String redirectUrl = getTypeAdminSectionMismatchUrl(typedEntity, typedEntitySection.getCeilingEntity(), request.getRequestURI(), sectionKey);
response.sendRedirect(redirectUrl);
return true;
}
// Check if admin user has access to this section.
if (!adminUserHasAccess(typedEntitySection)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access is denied");
return true;
}
// Add the typed entity admin section to the request.
request.setAttribute("typedEntitySection", typedEntitySection);
// Find the type and build the new path.
String type = getEntityTypeFromRequest(request);
final String forwardPath = servletPath.replace(type, "");
// Get the type field name on the Entity for the given section.
String typedFieldName = getTypeFieldName(typedEntitySection);
// Build out the new parameter map to be forwarded.
final Map parameters = new LinkedHashMap(request.getParameterMap());
if (typedFieldName != null) {
parameters.put(typedFieldName, new String[] { type.substring(1).toUpperCase() });
}
// Build our request wrapper.
final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
@Override
public String getParameter(String name) {
String[] response = (String[]) parameters.get(name);
if (ArrayUtils.isEmpty(response)) {
return null;
} else {
return response[0];
}
}
@Override
public Map getParameterMap() {
return parameters;
}
@Override
public Enumeration getParameterNames() {
return new IteratorEnumeration(parameters.keySet().iterator());
}
@Override
public String[] getParameterValues(String name) {
return (String[]) parameters.get(name);
}
@Override
public String getServletPath() {
return forwardPath;
}
};
requestProcessor.process(new ServletWebRequest(wrapper, response));
// Forward the wrapper to the appropriate path
wrapper.getRequestDispatcher(wrapper.getServletPath()).forward(wrapper, response);
return true;
}
Aggregations