Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-99625 Change operation to change the experiment status to POST and use a JSON body #76900

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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<String, Exception> 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<String, ?> map) {
StringBuilder sb = new StringBuilder("{");

@SuppressWarnings("unchecked")
Set set = map.entrySet();

@SuppressWarnings("unchecked")
Iterator<Map.Entry<String, ?>> iterator = set.iterator();

while (iterator.hasNext()) {
Map.Entry<String, ?> 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();
}

}
Expand Up @@ -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;

Expand All @@ -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(
Expand Down
@@ -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<String, Exception> 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);
}

}
Expand Up @@ -163,7 +163,7 @@ public Map<String, Object> parseToMap(String json) {

_readWhileLastCharIsWhiteSpace();

map.put(key, _readValue());
map.put(key, _readValue(true));

_readWhileLastCharIsWhiteSpace();
}
Expand Down Expand Up @@ -353,6 +353,10 @@ private void _readNextChar() {
}

private Object _readValue() {
return _readValue(false);
}

private Object _readValue(boolean parseMaps) {
if (_lastChar == '[') {
return _readValueAsArray();
}
Expand All @@ -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();
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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;

Expand Down