You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by "Daniel Keir Haywood (Jira)" <ji...@apache.org> on 2021/07/22 04:51:00 UTC

[jira] [Updated] (ISIS-2813) TableColumnOrderingService using files

     [ https://issues.apache.org/jira/browse/ISIS-2813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Keir Haywood updated ISIS-2813:
--------------------------------------
    Description: 
where the file is named "Customer#orders.columnOrder.txt" (for Customer#orders) and looks like:
{code:java}
orderNum
placedOn
shipTo
numItems{code}
in other words the properties of the referenced entity Order to show as columns in the Customer's orders collection.

and similarly for standalone collections of `Customer.columnOrder.txt`:
{code:java}
customerNum
lastName
status
addressPostcode{code}

  was:
in its entirety:
{code:java}
@Service
@Priority(PriorityPrecedence.MIDPOINT)
@RequiredArgsConstructor
@Log4j2
public class TableColumnOrderServiceUsingFiles implements TableColumnOrderService {

  final UserDetailCurrentService userDetailCurrentService;

  static final String LINE_SEPARATOR = System.getProperty("line.separator");

  @Override
  public List<String> orderParented(
      final Object domainObject,
      final String collectionId,
      final Class<?> collectionType,
      final List<String> propertyIds) {

    val domainClass = domainObject.getClass();
    val resourceNames = buildResourceNames(collectionId, domainClass);
    val contentsIfAny = tryLoad(domainClass, resourceNames);
    return contentsIfAny.map(s -> s.split(LINE_SEPARATOR)).map(Arrays::asList).orElse(null);
  }

  private List<String> buildResourceNames(String collectionId, Class<?> domainClass) {
    final List<String> resourceNames = new ArrayList<>();
    final String resourceName =
        String.format("%s.%s.txt", domainClass.getSimpleName(), collectionId);
    resourceNames.add(resourceName);
    userDetailCurrentService.currentUserPrimaryRoleName().ifPresent(x ->
        resourceNames.add(
            String.format("%s.%s.%s.txt", domainClass.getSimpleName(), collectionId, x))
    );
    return resourceNames;
  }

  private Optional<String> tryLoad(Class<?> domainClass, List<String> resourceNames) {
    for (String resourceName : resourceNames) {
      try {
        final String contents = _Resources.loadAsStringUtf8(domainClass, resourceName);
        if (contents != null) {
          return Optional.of(contents);
        }
      } catch (Exception ignore) {
        // in most cases there won't be a file to load, so we just continue.
        // not an error condition, but we'll log it at lowest (trace) level.
        if (log.isTraceEnabled()) {
          log.trace("No resource file '" + resourceName + "' relative to " + domainClass.getName());
        }
      }
    }
    return Optional.empty();
  }

  @Override
  public List<String> orderStandalone(
      final Class<?> collectionType, final List<String> propertyIds) {
    return null;
  }
} {code}
where the file is named "Customer.orders.txt" (for Customer#orders) and looks like:
{code:java}
orderNum
placedOn
shipTo
numItems{code}
in other words the properties of the referenced entity Order to show as columns in the Customer's orders collection.


> TableColumnOrderingService using files
> --------------------------------------
>
>                 Key: ISIS-2813
>                 URL: https://issues.apache.org/jira/browse/ISIS-2813
>             Project: Isis
>          Issue Type: New Feature
>          Components: Isis Core
>    Affects Versions: 2.0.0-M5
>            Reporter: Daniel Keir Haywood
>            Assignee: Daniel Keir Haywood
>            Priority: Major
>             Fix For: 2.0.0-M6
>
>
> where the file is named "Customer#orders.columnOrder.txt" (for Customer#orders) and looks like:
> {code:java}
> orderNum
> placedOn
> shipTo
> numItems{code}
> in other words the properties of the referenced entity Order to show as columns in the Customer's orders collection.
> and similarly for standalone collections of `Customer.columnOrder.txt`:
> {code:java}
> customerNum
> lastName
> status
> addressPostcode{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)