Search in sources :

Example 16 with EntityType

use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.

the class EntityResourceReferenceResolver method resolve.

@Override
public EntityResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
    EntityResourceReference entityURL;
    // UC1: <action>/<entity reference type>/<entity reference>
    // UC2: <action>/<entity reference> ==> type = page
    // UC3: <entity reference> ==> type = page, action = view
    List<String> pathSegments = extendedURL.getSegments();
    String action = ACTION_VIEW;
    EntityType entityType;
    String entityReferenceAsString;
    if (pathSegments.size() == 3) {
        action = pathSegments.get(0);
        entityType = computeEntityType(pathSegments.get(1));
        entityReferenceAsString = pathSegments.get(2);
    } else if (pathSegments.size() == 2) {
        action = pathSegments.get(0);
        entityType = computeDefaultEntityType(action);
        entityReferenceAsString = pathSegments.get(1);
    } else if (pathSegments.size() == 1) {
        entityType = computeDefaultEntityType(action);
        entityReferenceAsString = pathSegments.get(0);
    } else {
        throw new CreateResourceReferenceException(String.format("Invalid Entity URL [%s]", extendedURL.serialize()));
    }
    // Convert the string representation of the Entity reference into a proper EntityResourceReference.
    entityURL = new EntityResourceReference(this.defaultEntityReferenceResolver.resolve(entityReferenceAsString, entityType), EntityResourceAction.fromString(action));
    return entityURL;
}
Also used : EntityType(org.xwiki.model.EntityType) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) CreateResourceReferenceException(org.xwiki.resource.CreateResourceReferenceException)

Aggregations

EntityType (org.xwiki.model.EntityType)16 EntityReference (org.xwiki.model.reference.EntityReference)11 Namespace (org.xwiki.component.namespace.Namespace)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SolrDocument (org.apache.solr.common.SolrDocument)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 InvalidEntityReferenceException (org.xwiki.model.reference.InvalidEntityReferenceException)1 CreateResourceReferenceException (org.xwiki.resource.CreateResourceReferenceException)1 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)1 SolrIndexerException (org.xwiki.search.solr.internal.api.SolrIndexerException)1 Right (org.xwiki.security.authorization.Right)1 DefaultTestAccessRule (org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestAccessRule)1