diff --git a/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/dto/v1_0/Status.java b/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/dto/v1_0/Status.java new file mode 100644 index 00000000000000..eaeb7844b23849 --- /dev/null +++ b/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/dto/v1_0/Status.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.segments.asah.rest.dto.v1_0; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +import com.liferay.petra.function.UnsafeSupplier; +import com.liferay.petra.string.StringBundler; +import com.liferay.portal.vulcan.graphql.annotation.GraphQLField; +import com.liferay.portal.vulcan.graphql.annotation.GraphQLName; + +import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import javax.annotation.Generated; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Javier Gamarra + * @generated + */ +@Generated("") +@GraphQLName("Status") +@JsonFilter("Liferay.Vulcan") +@XmlRootElement(name = "Status") +public class Status { + + @Schema + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @JsonIgnore + public void setStatus( + UnsafeSupplier statusUnsafeSupplier) { + + try { + status = statusUnsafeSupplier.get(); + } + catch (RuntimeException re) { + throw re; + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + @GraphQLField + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + protected String status; + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (!(object instanceof Status)) { + return false; + } + + Status status = (Status)object; + + return Objects.equals(toString(), status.toString()); + } + + @Override + public int hashCode() { + String string = toString(); + + return string.hashCode(); + } + + public String toString() { + StringBundler sb = new StringBundler(); + + sb.append("{"); + + if (status != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"status\": "); + + sb.append("\""); + + sb.append(_escape(status)); + + sb.append("\""); + } + + sb.append("}"); + + return sb.toString(); + } + + private static String _escape(Object object) { + String string = String.valueOf(object); + + return string.replaceAll("\"", "\\\\\""); + } + + private static String _toJSON(Map map) { + StringBuilder sb = new StringBuilder("{"); + + @SuppressWarnings("unchecked") + Set set = map.entrySet(); + + @SuppressWarnings("unchecked") + Iterator> iterator = set.iterator(); + + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + + sb.append("\""); + sb.append(entry.getKey()); + sb.append("\":"); + sb.append("\""); + sb.append(entry.getValue()); + sb.append("\""); + + if (iterator.hasNext()) { + sb.append(","); + } + } + + sb.append("}"); + + return sb.toString(); + } + +} \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/resource/v1_0/ExperimentResource.java b/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/resource/v1_0/StatusResource.java similarity index 91% rename from modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/resource/v1_0/ExperimentResource.java rename to modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/resource/v1_0/StatusResource.java index b131b2a690660b..10b1151b305115 100644 --- a/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/resource/v1_0/ExperimentResource.java +++ b/modules/apps/segments/segments-asah-rest-api/src/main/java/com/liferay/segments/asah/rest/resource/v1_0/StatusResource.java @@ -18,6 +18,7 @@ import com.liferay.portal.kernel.model.User; import com.liferay.portal.vulcan.accept.language.AcceptLanguage; import com.liferay.segments.asah.rest.dto.v1_0.Experiment; +import com.liferay.segments.asah.rest.dto.v1_0.Status; import javax.annotation.Generated; @@ -38,9 +39,9 @@ */ @Generated("") @ProviderType -public interface ExperimentResource { +public interface StatusResource { - public Experiment patchExperiment(Long experimentId, String string) + public Experiment postExperimentStatus(Long experimentId, Status status) throws Exception; public default void setContextAcceptLanguage( diff --git a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/dto/v1_0/Status.java b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/dto/v1_0/Status.java new file mode 100644 index 00000000000000..100098987e0f34 --- /dev/null +++ b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/dto/v1_0/Status.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.segments.asah.rest.client.dto.v1_0; + +import com.liferay.segments.asah.rest.client.function.UnsafeSupplier; +import com.liferay.segments.asah.rest.client.serdes.v1_0.StatusSerDes; + +import java.util.Objects; + +import javax.annotation.Generated; + +/** + * @author Javier Gamarra + * @generated + */ +@Generated("") +public class Status { + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public void setStatus( + UnsafeSupplier statusUnsafeSupplier) { + + try { + status = statusUnsafeSupplier.get(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String status; + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (!(object instanceof Status)) { + return false; + } + + Status status = (Status)object; + + return Objects.equals(toString(), status.toString()); + } + + @Override + public int hashCode() { + String string = toString(); + + return string.hashCode(); + } + + public String toString() { + return StatusSerDes.toJSON(this); + } + +} \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/json/BaseJSONParser.java b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/json/BaseJSONParser.java index c537a13b99820a..d97a006b476946 100644 --- a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/json/BaseJSONParser.java +++ b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/json/BaseJSONParser.java @@ -163,7 +163,7 @@ public Map parseToMap(String json) { _readWhileLastCharIsWhiteSpace(); - map.put(key, _readValue()); + map.put(key, _readValue(true)); _readWhileLastCharIsWhiteSpace(); } @@ -353,6 +353,10 @@ private void _readNextChar() { } private Object _readValue() { + return _readValue(false); + } + + private Object _readValue(boolean parseMaps) { if (_lastChar == '[') { return _readValueAsArray(); } @@ -368,6 +372,9 @@ else if (_lastChar == 'n') { else if (_lastChar == '"') { return _readValueAsString(); } + else if (parseMaps && _lastChar == '{') { + return parseToMap(_readValueAsStringJSON()); + } else if (_lastChar == '{') { return _readValueAsStringJSON(); } diff --git a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/resource/v1_0/ExperimentResource.java b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/resource/v1_0/StatusResource.java similarity index 76% rename from modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/resource/v1_0/ExperimentResource.java rename to modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/resource/v1_0/StatusResource.java index 246939fa7b0181..b7a86bb8bc9ad5 100644 --- a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/resource/v1_0/ExperimentResource.java +++ b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/resource/v1_0/StatusResource.java @@ -14,7 +14,7 @@ package com.liferay.segments.asah.rest.client.resource.v1_0; -import com.liferay.segments.asah.rest.client.dto.v1_0.Experiment; +import com.liferay.segments.asah.rest.client.dto.v1_0.Status; import com.liferay.segments.asah.rest.client.http.HttpInvoker; import java.util.LinkedHashMap; @@ -30,17 +30,18 @@ * @generated */ @Generated("") -public interface ExperimentResource { +public interface StatusResource { public static Builder builder() { return new Builder(); } - public Experiment patchExperiment(Long experimentId, String string) + public com.liferay.segments.asah.rest.client.dto.v1_0.Experiment + postExperimentStatus(Long experimentId, Status status) throws Exception; - public HttpInvoker.HttpResponse patchExperimentHttpResponse( - Long experimentId, String string) + public HttpInvoker.HttpResponse postExperimentStatusHttpResponse( + Long experimentId, Status status) throws Exception; public static class Builder { @@ -52,8 +53,8 @@ public Builder authentication(String login, String password) { return this; } - public ExperimentResource build() { - return new ExperimentResourceImpl(this); + public StatusResource build() { + return new StatusResourceImpl(this); } public Builder endpoint(String host, int port, String scheme) { @@ -96,13 +97,14 @@ private Builder() { } - public static class ExperimentResourceImpl implements ExperimentResource { + public static class StatusResourceImpl implements StatusResource { - public Experiment patchExperiment(Long experimentId, String string) + public com.liferay.segments.asah.rest.client.dto.v1_0.Experiment + postExperimentStatus(Long experimentId, Status status) throws Exception { - HttpInvoker.HttpResponse httpResponse = patchExperimentHttpResponse( - experimentId, string); + HttpInvoker.HttpResponse httpResponse = + postExperimentStatusHttpResponse(experimentId, status); String content = httpResponse.getContent(); @@ -125,13 +127,13 @@ public Experiment patchExperiment(Long experimentId, String string) } } - public HttpInvoker.HttpResponse patchExperimentHttpResponse( - Long experimentId, String string) + public HttpInvoker.HttpResponse postExperimentStatusHttpResponse( + Long experimentId, Status status) throws Exception { HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker(); - httpInvoker.body(string.toString(), "application/json"); + httpInvoker.body(status.toString(), "application/json"); if (_builder._locale != null) { httpInvoker.header( @@ -150,12 +152,12 @@ public HttpInvoker.HttpResponse patchExperimentHttpResponse( httpInvoker.parameter(entry.getKey(), entry.getValue()); } - httpInvoker.httpMethod(HttpInvoker.HttpMethod.PATCH); + httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST); httpInvoker.path( _builder._scheme + "://" + _builder._host + ":" + _builder._port + - "/o/segments-asah/v1.0/experiments/{experimentId}", + "/o/segments-asah/v1.0/experiments/{experimentId}/status", experimentId); httpInvoker.userNameAndPassword( @@ -164,12 +166,12 @@ public HttpInvoker.HttpResponse patchExperimentHttpResponse( return httpInvoker.invoke(); } - private ExperimentResourceImpl(Builder builder) { + private StatusResourceImpl(Builder builder) { _builder = builder; } private static final Logger _logger = Logger.getLogger( - ExperimentResource.class.getName()); + StatusResource.class.getName()); private Builder _builder; diff --git a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/ExperimentSerDes.java b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/ExperimentSerDes.java index 121a5cbb2ac66d..e83933bb5c2bf1 100644 --- a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/ExperimentSerDes.java +++ b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/ExperimentSerDes.java @@ -245,17 +245,42 @@ private static String _toJSON(Map map) { sb.append("\""); sb.append(entry.getKey()); sb.append("\":"); - sb.append("\""); - if (entry.getValue() instanceof String) { + Object value = entry.getValue(); + + Class valueClass = value.getClass(); + + if (value instanceof Map) { + sb.append(_toJSON((Map)value)); + } + else if (value instanceof String) { + sb.append("\""); sb.append(_escape(entry.getValue())); + sb.append("\""); + } + else if (valueClass.isArray()) { + Object[] values = (Object[])value; + + sb.append("["); + + for (int i = 0; i < values.length; i++) { + sb.append("\""); + sb.append(_escape(values[i])); + sb.append("\""); + + if ((i + 1) < values.length) { + sb.append(", "); + } + } + + sb.append("]"); } else { + sb.append("\""); sb.append(entry.getValue()); + sb.append("\""); } - sb.append("\""); - if (iterator.hasNext()) { sb.append(","); } diff --git a/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/StatusSerDes.java b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/StatusSerDes.java new file mode 100644 index 00000000000000..d99c021209c7f9 --- /dev/null +++ b/modules/apps/segments/segments-asah-rest-client/src/main/java/com/liferay/segments/asah/rest/client/serdes/v1_0/StatusSerDes.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.segments.asah.rest.client.serdes.v1_0; + +import com.liferay.segments.asah.rest.client.dto.v1_0.Status; +import com.liferay.segments.asah.rest.client.json.BaseJSONParser; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import javax.annotation.Generated; + +/** + * @author Javier Gamarra + * @generated + */ +@Generated("") +public class StatusSerDes { + + public static Status toDTO(String json) { + StatusJSONParser statusJSONParser = new StatusJSONParser(); + + return statusJSONParser.parseToDTO(json); + } + + public static Status[] toDTOs(String json) { + StatusJSONParser statusJSONParser = new StatusJSONParser(); + + return statusJSONParser.parseToDTOs(json); + } + + public static String toJSON(Status status) { + if (status == null) { + return "null"; + } + + StringBuilder sb = new StringBuilder(); + + sb.append("{"); + + if (status.getStatus() != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"status\": "); + + sb.append("\""); + + sb.append(_escape(status.getStatus())); + + sb.append("\""); + } + + sb.append("}"); + + return sb.toString(); + } + + public static Map toMap(String json) { + StatusJSONParser statusJSONParser = new StatusJSONParser(); + + return statusJSONParser.parseToMap(json); + } + + public static Map toMap(Status status) { + if (status == null) { + return null; + } + + Map map = new HashMap<>(); + + if (status.getStatus() == null) { + map.put("status", null); + } + else { + map.put("status", String.valueOf(status.getStatus())); + } + + return map; + } + + private static String _escape(Object object) { + String string = String.valueOf(object); + + string = string.replace("\\", "\\\\"); + + return string.replace("\"", "\\\""); + } + + private static String _toJSON(Map map) { + StringBuilder sb = new StringBuilder("{"); + + @SuppressWarnings("unchecked") + Set set = map.entrySet(); + + @SuppressWarnings("unchecked") + Iterator> iterator = set.iterator(); + + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + + sb.append("\""); + sb.append(entry.getKey()); + sb.append("\":"); + + Object value = entry.getValue(); + + Class valueClass = value.getClass(); + + if (value instanceof Map) { + sb.append(_toJSON((Map)value)); + } + else if (value instanceof String) { + sb.append("\""); + sb.append(_escape(entry.getValue())); + sb.append("\""); + } + else if (valueClass.isArray()) { + Object[] values = (Object[])value; + + sb.append("["); + + for (int i = 0; i < values.length; i++) { + sb.append("\""); + sb.append(_escape(values[i])); + sb.append("\""); + + if ((i + 1) < values.length) { + sb.append(", "); + } + } + + sb.append("]"); + } + else { + sb.append("\""); + sb.append(entry.getValue()); + sb.append("\""); + } + + if (iterator.hasNext()) { + sb.append(","); + } + } + + sb.append("}"); + + return sb.toString(); + } + + private static class StatusJSONParser extends BaseJSONParser { + + @Override + protected Status createDTO() { + return new Status(); + } + + @Override + protected Status[] createDTOArray(int size) { + return new Status[size]; + } + + @Override + protected void setField( + Status status, String jsonParserFieldName, + Object jsonParserFieldValue) { + + if (Objects.equals(jsonParserFieldName, "status")) { + if (jsonParserFieldValue != null) { + status.setStatus((String)jsonParserFieldValue); + } + } + else { + throw new IllegalArgumentException( + "Unsupported field name " + jsonParserFieldName); + } + } + + } + +} \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-impl/rest-openapi.yaml b/modules/apps/segments/segments-asah-rest-impl/rest-openapi.yaml index e666f214273540..cccf6ce39b3d86 100644 --- a/modules/apps/segments/segments-asah-rest-impl/rest-openapi.yaml +++ b/modules/apps/segments/segments-asah-rest-impl/rest-openapi.yaml @@ -20,16 +20,20 @@ components: type: integer status: type: string + Status: + properties: + status: + type: string + type: object info: description: "" title: "Segments Asah" version: v1.0 openapi: 3.0.1 paths: - "/experiments/{experimentId}": - patch: - description: "" - operationId: patchExperiment + "/experiments/{experimentId}/status": + post: + operationId: postExperimentStatus parameters: - in: path name: experimentId @@ -39,9 +43,12 @@ paths: type: integer requestBody: content: - text/plain: + application/json: + schema: + $ref: "#/components/schemas/Status" + application/xml: schema: - type: string + $ref: "#/components/schemas/Status" responses: 200: content: @@ -52,4 +59,4 @@ paths: schema: $ref: "#/components/schemas/Experiment" description: "" - tags: ["Experiment"] \ No newline at end of file + tags: ["Status"] \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/mutation/v1_0/Mutation.java b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/mutation/v1_0/Mutation.java index e8d2b7d3918c09..4f628dfea256aa 100644 --- a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/mutation/v1_0/Mutation.java +++ b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/mutation/v1_0/Mutation.java @@ -21,7 +21,8 @@ import com.liferay.portal.vulcan.graphql.annotation.GraphQLField; import com.liferay.portal.vulcan.graphql.annotation.GraphQLName; import com.liferay.segments.asah.rest.dto.v1_0.Experiment; -import com.liferay.segments.asah.rest.resource.v1_0.ExperimentResource; +import com.liferay.segments.asah.rest.dto.v1_0.Status; +import com.liferay.segments.asah.rest.resource.v1_0.StatusResource; import javax.annotation.Generated; @@ -34,26 +35,25 @@ @Generated("") public class Mutation { - public static void setExperimentResourceComponentServiceObjects( - ComponentServiceObjects - experimentResourceComponentServiceObjects) { + public static void setStatusResourceComponentServiceObjects( + ComponentServiceObjects + statusResourceComponentServiceObjects) { - _experimentResourceComponentServiceObjects = - experimentResourceComponentServiceObjects; + _statusResourceComponentServiceObjects = + statusResourceComponentServiceObjects; } @GraphQLField - @GraphQLName("patchExperimentExperimentIdString") - public Experiment patchExperiment( + public Experiment createExperimentStatus( @GraphQLName("experimentId") Long experimentId, - @GraphQLName("string") String string) + @GraphQLName("status") Status status) throws Exception { return _applyComponentServiceObjects( - _experimentResourceComponentServiceObjects, + _statusResourceComponentServiceObjects, this::_populateResourceContext, - experimentResource -> experimentResource.patchExperiment( - experimentId, string)); + statusResource -> statusResource.postExperimentStatus( + experimentId, status)); } private R @@ -94,15 +94,15 @@ public Experiment patchExperiment( } } - private void _populateResourceContext(ExperimentResource experimentResource) + private void _populateResourceContext(StatusResource statusResource) throws Exception { - experimentResource.setContextAcceptLanguage(_acceptLanguage); - experimentResource.setContextCompany(_company); + statusResource.setContextAcceptLanguage(_acceptLanguage); + statusResource.setContextCompany(_company); } - private static ComponentServiceObjects - _experimentResourceComponentServiceObjects; + private static ComponentServiceObjects + _statusResourceComponentServiceObjects; private AcceptLanguage _acceptLanguage; private Company _company; diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/query/v1_0/Query.java b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/query/v1_0/Query.java index ae0d254d5e1dcd..eb70a40775921f 100644 --- a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/query/v1_0/Query.java +++ b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/query/v1_0/Query.java @@ -29,6 +29,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.UriInfo; + import org.osgi.service.component.ComponentServiceObjects; /** @@ -63,6 +65,7 @@ public class Query { private Company _company; private HttpServletRequest _httpServletRequest; private HttpServletResponse _httpServletResponse; + private UriInfo _uriInfo; private User _user; } \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/servlet/v1_0/ServletDataImpl.java b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/servlet/v1_0/ServletDataImpl.java index 005d3286acd698..91a57bc30d1b7d 100644 --- a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/servlet/v1_0/ServletDataImpl.java +++ b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/graphql/servlet/v1_0/ServletDataImpl.java @@ -17,7 +17,7 @@ import com.liferay.portal.vulcan.graphql.servlet.ServletData; import com.liferay.segments.asah.rest.internal.graphql.mutation.v1_0.Mutation; import com.liferay.segments.asah.rest.internal.graphql.query.v1_0.Query; -import com.liferay.segments.asah.rest.resource.v1_0.ExperimentResource; +import com.liferay.segments.asah.rest.resource.v1_0.StatusResource; import javax.annotation.Generated; @@ -38,8 +38,8 @@ public class ServletDataImpl implements ServletData { @Activate public void activate(BundleContext bundleContext) { - Mutation.setExperimentResourceComponentServiceObjects( - _experimentResourceComponentServiceObjects); + Mutation.setStatusResourceComponentServiceObjects( + _statusResourceComponentServiceObjects); } @Override @@ -62,7 +62,7 @@ public Query getQuery() { } @Reference(scope = ReferenceScope.PROTOTYPE_REQUIRED) - private ComponentServiceObjects - _experimentResourceComponentServiceObjects; + private ComponentServiceObjects + _statusResourceComponentServiceObjects; } \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/BaseExperimentResourceImpl.java b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/BaseStatusResourceImpl.java similarity index 83% rename from modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/BaseExperimentResourceImpl.java rename to modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/BaseStatusResourceImpl.java index 203b48d921097e..fd56c8c7004ae1 100644 --- a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/BaseExperimentResourceImpl.java +++ b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/BaseStatusResourceImpl.java @@ -20,9 +20,9 @@ import com.liferay.portal.vulcan.accept.language.AcceptLanguage; import com.liferay.portal.vulcan.util.TransformUtil; import com.liferay.segments.asah.rest.dto.v1_0.Experiment; -import com.liferay.segments.asah.rest.resource.v1_0.ExperimentResource; +import com.liferay.segments.asah.rest.dto.v1_0.Status; +import com.liferay.segments.asah.rest.resource.v1_0.StatusResource; -import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.enums.ParameterIn; @@ -39,7 +39,7 @@ import javax.validation.constraints.NotNull; import javax.ws.rs.Consumes; -import javax.ws.rs.PATCH; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -51,22 +51,26 @@ */ @Generated("") @Path("/v1.0") -public abstract class BaseExperimentResourceImpl implements ExperimentResource { +public abstract class BaseStatusResourceImpl implements StatusResource { + /** + * Invoke this method with the command line: + * + * curl -X 'POST' 'http://localhost:8080/o/segments-asah/v1.0/experiments/{experimentId}/status' -d $'{"status": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' + */ @Override - @Consumes("text/plain") - @Operation(description = "") - @PATCH + @Consumes({"application/json", "application/xml"}) + @POST @Parameters( value = {@Parameter(in = ParameterIn.PATH, name = "experimentId")} ) - @Path("/experiments/{experimentId}") + @Path("/experiments/{experimentId}/status") @Produces({"application/json", "application/xml"}) - @Tags(value = {@Tag(name = "Experiment")}) - public Experiment patchExperiment( + @Tags(value = {@Tag(name = "Status")}) + public Experiment postExperimentStatus( @NotNull @Parameter(hidden = true) @PathParam("experimentId") Long experimentId, - String string) + Status status) throws Exception { return new Experiment(); @@ -100,8 +104,7 @@ public void setContextUser(User contextUser) { this.contextUser = contextUser; } - protected void preparePatch( - Experiment experiment, Experiment existingExperiment) { + protected void preparePatch(Status status, Status existingStatus) { } protected List transform( diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/OpenAPIResourceImpl.java b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/OpenAPIResourceImpl.java index c3c9f80e461c01..e57bc190662522 100644 --- a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/OpenAPIResourceImpl.java +++ b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/OpenAPIResourceImpl.java @@ -64,7 +64,7 @@ public Response getOpenAPI(@PathParam("type") String type) private final Set> _resourceClasses = new HashSet>() { { - add(ExperimentResourceImpl.class); + add(StatusResourceImpl.class); add(OpenAPIResourceImpl.class); } diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/ExperimentResourceImpl.java b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/StatusResourceImpl.java similarity index 85% rename from modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/ExperimentResourceImpl.java rename to modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/StatusResourceImpl.java index 2ba70ec3b043ea..d9d80c6fc03446 100644 --- a/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/ExperimentResourceImpl.java +++ b/modules/apps/segments/segments-asah-rest-impl/src/main/java/com/liferay/segments/asah/rest/internal/resource/v1_0/StatusResourceImpl.java @@ -18,7 +18,8 @@ import com.liferay.portal.kernel.service.ServiceContextThreadLocal; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.segments.asah.rest.dto.v1_0.Experiment; -import com.liferay.segments.asah.rest.resource.v1_0.ExperimentResource; +import com.liferay.segments.asah.rest.dto.v1_0.Status; +import com.liferay.segments.asah.rest.resource.v1_0.StatusResource; import com.liferay.segments.constants.SegmentsExperimentConstants; import com.liferay.segments.model.SegmentsExperiment; import com.liferay.segments.service.SegmentsExperimentService; @@ -33,13 +34,14 @@ * @author Javier Gamarra */ @Component( - properties = "OSGI-INF/liferay/rest/v1_0/experiment.properties", - scope = ServiceScope.PROTOTYPE, service = ExperimentResource.class + properties = "OSGI-INF/liferay/rest/v1_0/status.properties", + scope = ServiceScope.PROTOTYPE, service = StatusResource.class ) -public class ExperimentResourceImpl extends BaseExperimentResourceImpl { +public class StatusResourceImpl extends BaseStatusResourceImpl { @Override - public Experiment patchExperiment(Long segmentsExperimentKey, String status) + public Experiment postExperimentStatus( + Long segmentsExperimentKey, Status status) throws Exception { ServiceContext serviceContext = @@ -55,7 +57,8 @@ public Experiment patchExperiment(Long segmentsExperimentKey, String status) return _toExperiment( _segmentsExperimentService.updateSegmentsExperiment( - String.valueOf(segmentsExperimentKey), _parseStatus(status))); + String.valueOf(segmentsExperimentKey), + _parseStatus(status.getStatus()))); } private int _parseStatus(String status) { diff --git a/modules/apps/segments/segments-asah-rest-impl/src/main/resources/OSGI-INF/liferay/rest/v1_0/experiment.properties b/modules/apps/segments/segments-asah-rest-impl/src/main/resources/OSGI-INF/liferay/rest/v1_0/status.properties similarity index 100% rename from modules/apps/segments/segments-asah-rest-impl/src/main/resources/OSGI-INF/liferay/rest/v1_0/experiment.properties rename to modules/apps/segments/segments-asah-rest-impl/src/main/resources/OSGI-INF/liferay/rest/v1_0/status.properties diff --git a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/BaseExperimentGraphQLTestCase.java b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/BaseStatusGraphQLTestCase.java similarity index 68% rename from modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/BaseExperimentGraphQLTestCase.java rename to modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/BaseStatusGraphQLTestCase.java index c45f68a882386f..59d14f7291aa68 100644 --- a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/BaseExperimentGraphQLTestCase.java +++ b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/BaseStatusGraphQLTestCase.java @@ -14,6 +14,7 @@ package com.liferay.segments.asah.rest.graphql.v1_0.test; +import com.liferay.portal.kernel.json.JSONArray; import com.liferay.portal.kernel.json.JSONObject; import com.liferay.portal.kernel.json.JSONUtil; import com.liferay.portal.kernel.model.Company; @@ -22,11 +23,10 @@ import com.liferay.portal.kernel.test.util.GroupTestUtil; import com.liferay.portal.kernel.test.util.RandomTestUtil; import com.liferay.portal.test.rule.LiferayIntegrationTestRule; -import com.liferay.segments.asah.rest.client.dto.v1_0.Experiment; +import com.liferay.segments.asah.rest.client.dto.v1_0.Status; import com.liferay.segments.asah.rest.client.http.HttpInvoker; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,6 +35,7 @@ import javax.annotation.Generated; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -44,7 +45,7 @@ * @generated */ @Generated("") -public abstract class BaseExperimentGraphQLTestCase { +public abstract class BaseStatusGraphQLTestCase { @ClassRule @Rule @@ -64,60 +65,30 @@ public void tearDown() throws Exception { GroupTestUtil.deleteGroup(testGroup); } - protected boolean equals(Experiment experiment, JSONObject jsonObject) { - List fieldNames = new ArrayList( - Arrays.asList(getAdditionalAssertFieldNames())); + protected void assertEqualsIgnoringOrder( + List statuses, JSONArray jsonArray) { - fieldNames.add("id"); + for (Status status : statuses) { + boolean contains = false; - for (String fieldName : fieldNames) { - if (Objects.equals("description", fieldName)) { - if (!Objects.equals( - experiment.getDescription(), - (String)jsonObject.getString("description"))) { - - return false; - } - - continue; - } - - if (Objects.equals("id", fieldName)) { - if (!Objects.equals( - experiment.getId(), - (String)jsonObject.getString("id"))) { - - return false; - } - - continue; - } - - if (Objects.equals("name", fieldName)) { - if (!Objects.equals( - experiment.getName(), - (String)jsonObject.getString("name"))) { + for (Object object : jsonArray) { + if (equals(status, (JSONObject)object)) { + contains = true; - return false; + break; } - - continue; } - if (Objects.equals("siteId", fieldName)) { - if (!Objects.equals( - experiment.getSiteId(), - (Long)jsonObject.getLong("siteId"))) { - - return false; - } - - continue; - } + Assert.assertTrue( + jsonArray + " does not contain " + status, contains); + } + } + protected boolean equals(Status status, JSONObject jsonObject) { + for (String fieldName : getAdditionalAssertFieldNames()) { if (Objects.equals("status", fieldName)) { if (!Objects.equals( - experiment.getStatus(), + status.getStatus(), (String)jsonObject.getString("status"))) { return false; @@ -137,30 +108,28 @@ protected String[] getAdditionalAssertFieldNames() { return new String[0]; } - protected Experiment randomExperiment() throws Exception { - return new Experiment() { - { - dateCreated = RandomTestUtil.nextDate(); - dateModified = RandomTestUtil.nextDate(); - description = RandomTestUtil.randomString(); - id = RandomTestUtil.randomString(); - name = RandomTestUtil.randomString(); - siteId = testGroup.getGroupId(); - status = RandomTestUtil.randomString(); - } - }; - } + protected List getGraphQLFields() { + List graphQLFields = new ArrayList<>(); - protected Company testCompany; - protected Group testGroup; + graphQLFields.add(new GraphQLField("id")); - private String _invoke(String query) throws Exception { - HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker(); + for (String additionalAssertFieldName : + getAdditionalAssertFieldNames()) { + + graphQLFields.add(new GraphQLField(additionalAssertFieldName)); + } - JSONObject jsonObject = JSONUtil.put("query", query); + return graphQLFields; + } - httpInvoker.body(jsonObject.toString(), "application/json"); + protected String invoke(String query) throws Exception { + HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker(); + httpInvoker.body( + JSONUtil.put( + "query", query + ).toString(), + "application/json"); httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST); httpInvoker.path("http://localhost:8080/o/graphql"); httpInvoker.userNameAndPassword("test@liferay.com:test"); @@ -170,7 +139,23 @@ private String _invoke(String query) throws Exception { return httpResponse.getContent(); } - private class GraphQLField { + protected Status randomStatus() throws Exception { + return new Status() { + { + status = RandomTestUtil.randomString(); + } + }; + } + + protected Status testStatus_addStatus() throws Exception { + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + + protected Company testCompany; + protected Group testGroup; + + protected class GraphQLField { public GraphQLField(String key, GraphQLField... graphQLFields) { this(key, new HashMap<>(), graphQLFields); diff --git a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/ExperimentGraphQLTest.java b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/StatusGraphQLTest.java similarity index 91% rename from modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/ExperimentGraphQLTest.java rename to modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/StatusGraphQLTest.java index 3b60d49f7fbe00..1e75bc77f294ef 100644 --- a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/ExperimentGraphQLTest.java +++ b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/graphql/v1_0/test/StatusGraphQLTest.java @@ -24,5 +24,5 @@ */ @Ignore @RunWith(Arquillian.class) -public class ExperimentGraphQLTest extends BaseExperimentGraphQLTestCase { +public class StatusGraphQLTest extends BaseStatusGraphQLTestCase { } \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/BaseExperimentResourceTestCase.java b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/BaseStatusResourceTestCase.java similarity index 68% rename from modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/BaseExperimentResourceTestCase.java rename to modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/BaseStatusResourceTestCase.java index bfb86f7a11b7de..ad8a15ded26740 100644 --- a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/BaseExperimentResourceTestCase.java +++ b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/BaseStatusResourceTestCase.java @@ -39,10 +39,11 @@ import com.liferay.portal.test.rule.LiferayIntegrationTestRule; import com.liferay.portal.vulcan.resource.EntityModelResource; import com.liferay.segments.asah.rest.client.dto.v1_0.Experiment; +import com.liferay.segments.asah.rest.client.dto.v1_0.Status; import com.liferay.segments.asah.rest.client.http.HttpInvoker; import com.liferay.segments.asah.rest.client.pagination.Page; -import com.liferay.segments.asah.rest.client.resource.v1_0.ExperimentResource; -import com.liferay.segments.asah.rest.client.serdes.v1_0.ExperimentSerDes; +import com.liferay.segments.asah.rest.client.resource.v1_0.StatusResource; +import com.liferay.segments.asah.rest.client.serdes.v1_0.StatusSerDes; import java.lang.reflect.InvocationTargetException; @@ -59,7 +60,6 @@ import javax.ws.rs.core.MultivaluedHashMap; import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.lang.time.DateUtils; import org.junit.After; import org.junit.Assert; @@ -74,7 +74,7 @@ * @generated */ @Generated("") -public abstract class BaseExperimentResourceTestCase { +public abstract class BaseStatusResourceTestCase { @ClassRule @Rule @@ -95,11 +95,11 @@ public void setUp() throws Exception { testCompany = CompanyLocalServiceUtil.getCompany( testGroup.getCompanyId()); - _experimentResource.setContextCompany(testCompany); + _statusResource.setContextCompany(testCompany); - ExperimentResource.Builder builder = ExperimentResource.builder(); + StatusResource.Builder builder = StatusResource.builder(); - experimentResource = builder.locale( + statusResource = builder.locale( LocaleUtil.getDefault() ).build(); } @@ -128,13 +128,13 @@ public void testClientSerDesToDTO() throws Exception { } }; - Experiment experiment1 = randomExperiment(); + Status status1 = randomStatus(); - String json = objectMapper.writeValueAsString(experiment1); + String json = objectMapper.writeValueAsString(status1); - Experiment experiment2 = ExperimentSerDes.toDTO(json); + Status status2 = StatusSerDes.toDTO(json); - Assert.assertTrue(equals(experiment1, experiment2)); + Assert.assertTrue(equals(status1, status2)); } @Test @@ -154,10 +154,10 @@ public void testClientSerDesToJSON() throws Exception { } }; - Experiment experiment = randomExperiment(); + Status status = randomStatus(); - String json1 = objectMapper.writeValueAsString(experiment); - String json2 = ExperimentSerDes.toJSON(experiment); + String json1 = objectMapper.writeValueAsString(status); + String json2 = StatusSerDes.toJSON(status); Assert.assertEquals( objectMapper.readTree(json1), objectMapper.readTree(json2)); @@ -167,28 +167,22 @@ public void testClientSerDesToJSON() throws Exception { public void testEscapeRegexInStringFields() throws Exception { String regex = "^[0-9]+(\\.[0-9]{1,2})\"?"; - Experiment experiment = randomExperiment(); + Status status = randomStatus(); - experiment.setDescription(regex); - experiment.setId(regex); - experiment.setName(regex); - experiment.setStatus(regex); + status.setStatus(regex); - String json = ExperimentSerDes.toJSON(experiment); + String json = StatusSerDes.toJSON(status); Assert.assertFalse(json.contains(regex)); - experiment = ExperimentSerDes.toDTO(json); + status = StatusSerDes.toDTO(json); - Assert.assertEquals(regex, experiment.getDescription()); - Assert.assertEquals(regex, experiment.getId()); - Assert.assertEquals(regex, experiment.getName()); - Assert.assertEquals(regex, experiment.getStatus()); + Assert.assertEquals(regex, status.getStatus()); } @Test - public void testPatchExperiment() throws Exception { - Assert.assertTrue(false); + public void testPostExperimentStatus() throws Exception { + Assert.assertTrue(true); } protected void assertHttpResponseStatusCode( @@ -199,37 +193,42 @@ protected void assertHttpResponseStatusCode( expectedHttpResponseStatusCode, actualHttpResponse.getStatusCode()); } - protected void assertEquals( - Experiment experiment1, Experiment experiment2) { - + protected void assertEquals(Status status1, Status status2) { Assert.assertTrue( - experiment1 + " does not equal " + experiment2, - equals(experiment1, experiment2)); + status1 + " does not equal " + status2, equals(status1, status2)); } protected void assertEquals( - List experiments1, List experiments2) { + List statuses1, List statuses2) { - Assert.assertEquals(experiments1.size(), experiments2.size()); + Assert.assertEquals(statuses1.size(), statuses2.size()); - for (int i = 0; i < experiments1.size(); i++) { - Experiment experiment1 = experiments1.get(i); - Experiment experiment2 = experiments2.get(i); + for (int i = 0; i < statuses1.size(); i++) { + Status status1 = statuses1.get(i); + Status status2 = statuses2.get(i); - assertEquals(experiment1, experiment2); + assertEquals(status1, status2); } } + protected void assertEquals( + Experiment experiment1, Experiment experiment2) { + + Assert.assertTrue( + experiment1 + " does not equal " + experiment2, + equals(experiment1, experiment2)); + } + protected void assertEqualsIgnoringOrder( - List experiments1, List experiments2) { + List statuses1, List statuses2) { - Assert.assertEquals(experiments1.size(), experiments2.size()); + Assert.assertEquals(statuses1.size(), statuses2.size()); - for (Experiment experiment1 : experiments1) { + for (Status status1 : statuses1) { boolean contains = false; - for (Experiment experiment2 : experiments2) { - if (equals(experiment1, experiment2)) { + for (Status status2 : statuses2) { + if (equals(status1, status2)) { contains = true; break; @@ -237,8 +236,47 @@ protected void assertEqualsIgnoringOrder( } Assert.assertTrue( - experiments2 + " does not contain " + experiment1, contains); + statuses2 + " does not contain " + status1, contains); + } + } + + protected void assertValid(Status status) { + boolean valid = true; + + for (String additionalAssertFieldName : + getAdditionalAssertFieldNames()) { + + if (Objects.equals("status", additionalAssertFieldName)) { + if (status.getStatus() == null) { + valid = false; + } + + continue; + } + + throw new IllegalArgumentException( + "Invalid additional assert field name " + + additionalAssertFieldName); } + + Assert.assertTrue(valid); + } + + protected void assertValid(Page page) { + boolean valid = false; + + java.util.Collection statuses = page.getItems(); + + int size = statuses.size(); + + if ((page.getLastPage() > 0) && (page.getPage() > 0) && + (page.getPageSize() > 0) && (page.getTotalCount() > 0) && + (size > 0)) { + + valid = true; + } + + Assert.assertTrue(valid); } protected void assertValid(Experiment experiment) { @@ -261,7 +299,7 @@ protected void assertValid(Experiment experiment) { } for (String additionalAssertFieldName : - getAdditionalAssertFieldNames()) { + getAdditionalExperimentAssertFieldNames()) { if (Objects.equals("description", additionalAssertFieldName)) { if (experiment.getDescription() == null) { @@ -295,24 +333,11 @@ protected void assertValid(Experiment experiment) { Assert.assertTrue(valid); } - protected void assertValid(Page page) { - boolean valid = false; - - java.util.Collection experiments = page.getItems(); - - int size = experiments.size(); - - if ((page.getLastPage() > 0) && (page.getPage() > 0) && - (page.getPageSize() > 0) && (page.getTotalCount() > 0) && - (size > 0)) { - - valid = true; - } - - Assert.assertTrue(valid); + protected String[] getAdditionalAssertFieldNames() { + return new String[0]; } - protected String[] getAdditionalAssertFieldNames() { + protected String[] getAdditionalExperimentAssertFieldNames() { return new String[0]; } @@ -320,17 +345,39 @@ protected String[] getIgnoredEntityFieldNames() { return new String[0]; } - protected boolean equals(Experiment experiment1, Experiment experiment2) { - if (experiment1 == experiment2) { + protected boolean equals(Status status1, Status status2) { + if (status1 == status2) { return true; } - if (!Objects.equals(experiment1.getSiteId(), experiment2.getSiteId())) { - return false; + for (String additionalAssertFieldName : + getAdditionalAssertFieldNames()) { + + if (Objects.equals("status", additionalAssertFieldName)) { + if (!Objects.deepEquals( + status1.getStatus(), status2.getStatus())) { + + return false; + } + + continue; + } + + throw new IllegalArgumentException( + "Invalid additional assert field name " + + additionalAssertFieldName); + } + + return true; + } + + protected boolean equals(Experiment experiment1, Experiment experiment2) { + if (experiment1 == experiment2) { + return true; } for (String additionalAssertFieldName : - getAdditionalAssertFieldNames()) { + getAdditionalExperimentAssertFieldNames()) { if (Objects.equals("dateCreated", additionalAssertFieldName)) { if (!Objects.deepEquals( @@ -385,6 +432,16 @@ protected boolean equals(Experiment experiment1, Experiment experiment2) { continue; } + if (Objects.equals("siteId", additionalAssertFieldName)) { + if (!Objects.deepEquals( + experiment1.getSiteId(), experiment2.getSiteId())) { + + return false; + } + + continue; + } + if (Objects.equals("status", additionalAssertFieldName)) { if (!Objects.deepEquals( experiment1.getStatus(), experiment2.getStatus())) { @@ -406,13 +463,13 @@ protected boolean equals(Experiment experiment1, Experiment experiment2) { protected java.util.Collection getEntityFields() throws Exception { - if (!(_experimentResource instanceof EntityModelResource)) { + if (!(_statusResource instanceof EntityModelResource)) { throw new UnsupportedOperationException( "Resource is not an instance of EntityModelResource"); } EntityModelResource entityModelResource = - (EntityModelResource)_experimentResource; + (EntityModelResource)_statusResource; EntityModel entityModel = entityModelResource.getEntityModel( new MultivaluedHashMap()); @@ -441,7 +498,7 @@ protected List getEntityFields(EntityField.Type type) } protected String getFilterString( - EntityField entityField, String operator, Experiment experiment) { + EntityField entityField, String operator, Status status) { StringBundler sb = new StringBundler(); @@ -453,108 +510,34 @@ protected String getFilterString( sb.append(operator); sb.append(" "); - if (entityFieldName.equals("dateCreated")) { - if (operator.equals("between")) { - sb = new StringBundler(); - - sb.append("("); - sb.append(entityFieldName); - sb.append(" gt "); - sb.append( - _dateFormat.format( - DateUtils.addSeconds(experiment.getDateCreated(), -2))); - sb.append(" and "); - sb.append(entityFieldName); - sb.append(" lt "); - sb.append( - _dateFormat.format( - DateUtils.addSeconds(experiment.getDateCreated(), 2))); - sb.append(")"); - } - else { - sb.append(entityFieldName); - - sb.append(" "); - sb.append(operator); - sb.append(" "); - - sb.append(_dateFormat.format(experiment.getDateCreated())); - } - - return sb.toString(); - } - - if (entityFieldName.equals("dateModified")) { - if (operator.equals("between")) { - sb = new StringBundler(); - - sb.append("("); - sb.append(entityFieldName); - sb.append(" gt "); - sb.append( - _dateFormat.format( - DateUtils.addSeconds( - experiment.getDateModified(), -2))); - sb.append(" and "); - sb.append(entityFieldName); - sb.append(" lt "); - sb.append( - _dateFormat.format( - DateUtils.addSeconds(experiment.getDateModified(), 2))); - sb.append(")"); - } - else { - sb.append(entityFieldName); - - sb.append(" "); - sb.append(operator); - sb.append(" "); - - sb.append(_dateFormat.format(experiment.getDateModified())); - } - - return sb.toString(); - } - - if (entityFieldName.equals("description")) { - sb.append("'"); - sb.append(String.valueOf(experiment.getDescription())); - sb.append("'"); - - return sb.toString(); - } - - if (entityFieldName.equals("id")) { + if (entityFieldName.equals("status")) { sb.append("'"); - sb.append(String.valueOf(experiment.getId())); + sb.append(String.valueOf(status.getStatus())); sb.append("'"); return sb.toString(); } - if (entityFieldName.equals("name")) { - sb.append("'"); - sb.append(String.valueOf(experiment.getName())); - sb.append("'"); - - return sb.toString(); - } + throw new IllegalArgumentException( + "Invalid entity field " + entityFieldName); + } - if (entityFieldName.equals("siteId")) { - throw new IllegalArgumentException( - "Invalid entity field " + entityFieldName); - } + protected Status randomStatus() throws Exception { + return new Status() { + { + status = RandomTestUtil.randomString(); + } + }; + } - if (entityFieldName.equals("status")) { - sb.append("'"); - sb.append(String.valueOf(experiment.getStatus())); - sb.append("'"); + protected Status randomIrrelevantStatus() throws Exception { + Status randomIrrelevantStatus = randomStatus(); - return sb.toString(); - } + return randomIrrelevantStatus; + } - throw new IllegalArgumentException( - "Invalid entity field " + entityFieldName); + protected Status randomPatchStatus() throws Exception { + return randomStatus(); } protected Experiment randomExperiment() throws Exception { @@ -565,31 +548,19 @@ protected Experiment randomExperiment() throws Exception { description = RandomTestUtil.randomString(); id = RandomTestUtil.randomString(); name = RandomTestUtil.randomString(); - siteId = testGroup.getGroupId(); + siteId = RandomTestUtil.randomLong(); status = RandomTestUtil.randomString(); } }; } - protected Experiment randomIrrelevantExperiment() throws Exception { - Experiment randomIrrelevantExperiment = randomExperiment(); - - randomIrrelevantExperiment.setSiteId(irrelevantGroup.getGroupId()); - - return randomIrrelevantExperiment; - } - - protected Experiment randomPatchExperiment() throws Exception { - return randomExperiment(); - } - - protected ExperimentResource experimentResource; + protected StatusResource statusResource; protected Group irrelevantGroup; protected Company testCompany; protected Group testGroup; private static final Log _log = LogFactoryUtil.getLog( - BaseExperimentResourceTestCase.class); + BaseStatusResourceTestCase.class); private static BeanUtilsBean _beanUtilsBean = new BeanUtilsBean() { @@ -606,7 +577,7 @@ public void copyProperty(Object bean, String name, Object value) private static DateFormat _dateFormat; @Inject - private com.liferay.segments.asah.rest.resource.v1_0.ExperimentResource - _experimentResource; + private com.liferay.segments.asah.rest.resource.v1_0.StatusResource + _statusResource; } \ No newline at end of file diff --git a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/ExperimentResourceTest.java b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/StatusResourceTest.java similarity index 91% rename from modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/ExperimentResourceTest.java rename to modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/StatusResourceTest.java index 0ed90a4acda264..4a4661839a8b79 100644 --- a/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/ExperimentResourceTest.java +++ b/modules/apps/segments/segments-asah-rest-test/src/testIntegration/java/com/liferay/segments/asah/rest/resource/v1_0/test/StatusResourceTest.java @@ -24,5 +24,5 @@ */ @Ignore @RunWith(Arquillian.class) -public class ExperimentResourceTest extends BaseExperimentResourceTestCase { +public class StatusResourceTest extends BaseStatusResourceTestCase { } \ No newline at end of file