Search in sources :

Example 1 with Identifier

use of com.liferay.apio.architect.identifier.Identifier in project com-liferay-apio-architect by liferay.

the class MockWriterUtil method identifierToPath.

/**
 * Returns a mock {@link Path} from an identifier. The identifier must be a
 * {@link String}, otherwise {@code Optional#empty()} is returned.
 *
 * @param  identifier the identifier
 * @return the mock {@code Path} from the identifier, if the identifier is a
 *         {@code String}; {@code Optional#empty()} otherwise
 */
public static Optional<Path> identifierToPath(String resourceName, Object identifier) {
    if (!(identifier instanceof String)) {
        return Optional.empty();
    }
    String string = (String) identifier;
    Function<String, Optional<Path>> function = name -> Optional.of(new Path(name, string));
    if ("root".equals(resourceName)) {
        return function.apply("model");
    }
    if ("first".equals(resourceName)) {
        return function.apply("first-inner-model");
    }
    if ("second".equals(resourceName)) {
        return function.apply("second-inner-model");
    }
    return function.apply("third-inner-model");
}
Also used : MockRepresentorCreator.createFirstEmbeddedModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createFirstEmbeddedModelRepresentor) Arrays(java.util.Arrays) MockRepresentorCreator.createRootModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createRootModelRepresentor) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockRepresentorCreator.createThirdEmbeddedModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createThirdEmbeddedModelRepresentor) Path(com.liferay.apio.architect.uri.Path) Function(java.util.function.Function) MockRepresentorCreator.createSecondEmbeddedModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createSecondEmbeddedModelRepresentor) Operation(com.liferay.apio.architect.operation.Operation) Representor(com.liferay.apio.architect.representor.Representor) SecondEmbeddedId(com.liferay.apio.architect.test.util.identifier.SecondEmbeddedId) Identifier(com.liferay.apio.architect.identifier.Identifier) SecondEmbeddedModel(com.liferay.apio.architect.test.util.model.SecondEmbeddedModel) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Locale(java.util.Locale) DELETE(com.liferay.apio.architect.operation.Method.DELETE) Optional(java.util.Optional) SingleModel(com.liferay.apio.architect.single.model.SingleModel) FirstEmbeddedId(com.liferay.apio.architect.test.util.identifier.FirstEmbeddedId) FirstEmbeddedModel(com.liferay.apio.architect.test.util.model.FirstEmbeddedModel) Collections(java.util.Collections) ThirdEmbeddedId(com.liferay.apio.architect.test.util.identifier.ThirdEmbeddedId) ThirdEmbeddedModel(com.liferay.apio.architect.test.util.model.ThirdEmbeddedModel) Path(com.liferay.apio.architect.uri.Path) Optional(java.util.Optional)

Example 2 with Identifier

use of com.liferay.apio.architect.identifier.Identifier in project com-liferay-apio-architect by liferay.

the class RepresentableManagerImpl method emit.

@Override
protected void emit(ServiceReference<Representable> serviceReference, Emitter<Class<Identifier>> emitter) {
    Representable representable = bundleContext.getService(serviceReference);
    Class<Identifier> genericClass = getGenericClassFromPropertyOrElse(serviceReference, KEY_PRINCIPAL_TYPE_ARGUMENT, () -> getTypeParamOrFail(representable, Representable.class, 2));
    emitter.emit(genericClass);
}
Also used : Representable(com.liferay.apio.architect.representor.Representable) Identifier(com.liferay.apio.architect.identifier.Identifier)

Aggregations

Identifier (com.liferay.apio.architect.identifier.Identifier)2 DELETE (com.liferay.apio.architect.operation.Method.DELETE)1 Operation (com.liferay.apio.architect.operation.Operation)1 Representable (com.liferay.apio.architect.representor.Representable)1 Representor (com.liferay.apio.architect.representor.Representor)1 RequestInfo (com.liferay.apio.architect.request.RequestInfo)1 SingleModel (com.liferay.apio.architect.single.model.SingleModel)1 FirstEmbeddedId (com.liferay.apio.architect.test.util.identifier.FirstEmbeddedId)1 SecondEmbeddedId (com.liferay.apio.architect.test.util.identifier.SecondEmbeddedId)1 ThirdEmbeddedId (com.liferay.apio.architect.test.util.identifier.ThirdEmbeddedId)1 FirstEmbeddedModel (com.liferay.apio.architect.test.util.model.FirstEmbeddedModel)1 SecondEmbeddedModel (com.liferay.apio.architect.test.util.model.SecondEmbeddedModel)1 ThirdEmbeddedModel (com.liferay.apio.architect.test.util.model.ThirdEmbeddedModel)1 MockRepresentorCreator.createFirstEmbeddedModelRepresentor (com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createFirstEmbeddedModelRepresentor)1 MockRepresentorCreator.createRootModelRepresentor (com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createRootModelRepresentor)1 MockRepresentorCreator.createSecondEmbeddedModelRepresentor (com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createSecondEmbeddedModelRepresentor)1 MockRepresentorCreator.createThirdEmbeddedModelRepresentor (com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createThirdEmbeddedModelRepresentor)1 Path (com.liferay.apio.architect.uri.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1