[New] Versions.toJson() require boolean isAdminRequest, triggering what is added to the JSON
This commit is contained in:
parent
c4fd605c5b
commit
aba85f5d7c
|
@ -50,8 +50,8 @@ public class AgentVersion extends StrolchVersion {
|
|||
}
|
||||
|
||||
@Override
|
||||
public JsonObject toJson() {
|
||||
JsonObject jsonObject = super.toJson();
|
||||
public JsonObject toJson(boolean isAdminRequest) {
|
||||
JsonObject jsonObject = super.toJson(isAdminRequest);
|
||||
|
||||
jsonObject.addProperty(AGENT_NAME, this.agentName);
|
||||
jsonObject.addProperty(ENVIRONMENT, this.environment);
|
||||
|
@ -63,10 +63,10 @@ public class AgentVersion extends StrolchVersion {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AgentVersion{agentName='" + this.agentName + "' , environment='" + this.environment + "' , locale='"
|
||||
+ this.locale + "' , timezone='" + this.timezone + "' , groupId='" + getGroupId() + "' , artifactId='"
|
||||
+ getArtifactId() + "' , artifactVersion='" + getArtifactVersion() + "' , scmRevision='"
|
||||
+ getScmRevision() + "' , scmBranch='" + getScmBranch() + "' , buildTimestamp='" + getBuildTimestamp()
|
||||
+ "' }";
|
||||
return "AgentVersion{agentName='" + this.agentName + "' , environment='" + this.environment + "' , locale='" +
|
||||
this.locale + "' , timezone='" + this.timezone + "' , groupId='" + getGroupId() + "' , artifactId='" +
|
||||
getArtifactId() + "' , artifactVersion='" + getArtifactVersion() + "' , scmRevision='" +
|
||||
getScmRevision() + "' , scmBranch='" + getScmBranch() + "' , buildTimestamp='" + getBuildTimestamp() +
|
||||
"' }";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ public class ComponentVersion extends StrolchVersion {
|
|||
}
|
||||
|
||||
@Override
|
||||
public JsonObject toJson() {
|
||||
JsonObject jsonObject = super.toJson();
|
||||
public JsonObject toJson(boolean isAdminRequest) {
|
||||
JsonObject jsonObject = super.toJson(isAdminRequest);
|
||||
|
||||
jsonObject.addProperty(COMPONENT_NAME, this.componentName);
|
||||
|
||||
|
@ -52,9 +52,9 @@ public class ComponentVersion extends StrolchVersion {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComponentVersion{componentName='" + this.componentName + "' , groupId='" + getGroupId()
|
||||
+ "' , artifactId='" + getArtifactId() + "' , artifactVersion='" + getArtifactVersion()
|
||||
+ "' , scmRevision='" + getScmRevision() + "' , scmBranch='" + getScmBranch() + "' , buildTimestamp='"
|
||||
+ getBuildTimestamp() + "' }";
|
||||
return "ComponentVersion{componentName='" + this.componentName + "' , groupId='" + getGroupId() +
|
||||
"' , artifactId='" + getArtifactId() + "' , artifactVersion='" + getArtifactVersion() +
|
||||
"' , scmRevision='" + getScmRevision() + "' , scmBranch='" + getScmBranch() + "' , buildTimestamp='" +
|
||||
getBuildTimestamp() + "' }";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,23 +90,25 @@ public class StrolchVersion {
|
|||
this.buildTimestamp = buildTimestamp;
|
||||
}
|
||||
|
||||
public JsonObject toJson() {
|
||||
public JsonObject toJson(boolean isAdminRequest) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
jsonObject.addProperty(GROUP_ID, this.groupId);
|
||||
jsonObject.addProperty(ARTIFACT_ID, this.artifactId);
|
||||
jsonObject.addProperty(ARTIFACT_VERSION, this.artifactVersion);
|
||||
jsonObject.addProperty(SCM_REVISION, this.scmRevision);
|
||||
jsonObject.addProperty(SCM_BRANCH, this.scmBranch);
|
||||
jsonObject.addProperty(BUILD_TIMESTAMP, this.buildTimestamp);
|
||||
if (isAdminRequest) {
|
||||
jsonObject.addProperty(SCM_REVISION, this.scmRevision);
|
||||
jsonObject.addProperty(SCM_BRANCH, this.scmBranch);
|
||||
jsonObject.addProperty(BUILD_TIMESTAMP, this.buildTimestamp);
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StrolchVersion{groupId='" + groupId + "' , artifactId='" + artifactId + "', artifactVersion='"
|
||||
+ artifactVersion + "' , scmRevision='" + scmRevision + "' , scmBranch='" + scmBranch
|
||||
+ "' , buildTimestamp='" + buildTimestamp + "' }";
|
||||
return "StrolchVersion{groupId='" + groupId + "' , artifactId='" + artifactId + "', artifactVersion='" +
|
||||
artifactVersion + "' , scmRevision='" + scmRevision + "' , scmBranch='" + scmBranch +
|
||||
"' , buildTimestamp='" + buildTimestamp + "' }";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
*/
|
||||
package li.strolch.agent.api;
|
||||
|
||||
import static li.strolch.model.Tags.Json.*;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import static li.strolch.model.Tags.Json.*;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -83,20 +83,22 @@ public class VersionQueryResult {
|
|||
return this.errors != null && !this.errors.isEmpty();
|
||||
}
|
||||
|
||||
public JsonObject toJson() {
|
||||
public JsonObject toJson(boolean isAdminRequest) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
jsonObject.add(APP_VERSION, this.appVersion.toJson());
|
||||
jsonObject.add(AGENT_VERSION, this.agentVersion.toJson());
|
||||
jsonObject.add(APP_VERSION, this.appVersion.toJson(isAdminRequest));
|
||||
jsonObject.add(AGENT_VERSION, this.agentVersion.toJson(isAdminRequest));
|
||||
|
||||
JsonArray componentVersionsJ = new JsonArray();
|
||||
this.componentVersions.forEach(c -> componentVersionsJ.add(c.toJson()));
|
||||
jsonObject.add(COMPONENT_VERSIONS, componentVersionsJ);
|
||||
if (isAdminRequest) {
|
||||
JsonArray componentVersionsJ = new JsonArray();
|
||||
this.componentVersions.forEach(c -> componentVersionsJ.add(c.toJson(true)));
|
||||
jsonObject.add(COMPONENT_VERSIONS, componentVersionsJ);
|
||||
|
||||
if (this.errors != null) {
|
||||
JsonArray errorsJ = new JsonArray();
|
||||
this.errors.forEach(errorsJ::add);
|
||||
jsonObject.add(ERRORS, errorsJ);
|
||||
if (this.errors != null) {
|
||||
JsonArray errorsJ = new JsonArray();
|
||||
this.errors.forEach(errorsJ::add);
|
||||
jsonObject.add(ERRORS, errorsJ);
|
||||
}
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package li.strolch.rest.endpoint;
|
||||
|
||||
import static li.strolch.model.StrolchModelConstants.ROLE_STROLCH_ADMIN;
|
||||
import static li.strolch.model.Tags.Json.*;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -28,6 +29,7 @@ import jakarta.ws.rs.core.Response;
|
|||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.model.StrolchModelConstants;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
import li.strolch.rest.StrolchRestfulConstants;
|
||||
|
@ -44,29 +46,22 @@ public class VersionQuery {
|
|||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
StrolchAgent agent = RestfulStrolchComponent.getInstance().getAgent();
|
||||
|
||||
if (cert == null && RestfulStrolchComponent.getInstance().isHideVersionFromUnauthorizedClients()) {
|
||||
|
||||
JsonObject agentVersion = new JsonObject();
|
||||
agentVersion.addProperty(AGENT_NAME, agent.getApplicationName());
|
||||
agentVersion.addProperty(ENVIRONMENT, agent.getEnvironment());
|
||||
agentVersion.addProperty(LOCALE, agent.getLocale().toLanguageTag());
|
||||
agentVersion.addProperty(TIMEZONE, agent.getTimezone());
|
||||
|
||||
JsonArray componentVersionsJ = new JsonArray();
|
||||
agent.getVersion().getComponentVersions().forEach(c -> {
|
||||
JsonObject componentVersionJ = new JsonObject();
|
||||
componentVersionJ.addProperty(COMPONENT_NAME, c.getComponentName());
|
||||
componentVersionsJ.add(componentVersionJ);
|
||||
});
|
||||
|
||||
if (cert == null) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
JsonObject agentVersion = agent.getVersion().getAgentVersion().toJson(false);
|
||||
jsonObject.add(AGENT_VERSION, agentVersion);
|
||||
jsonObject.add(APP_VERSION, new JsonObject());
|
||||
jsonObject.add(COMPONENT_VERSIONS, componentVersionsJ);
|
||||
|
||||
if (RestfulStrolchComponent.getInstance().isHideVersionFromUnauthorizedClients()) {
|
||||
jsonObject.add(APP_VERSION, new JsonObject());
|
||||
} else {
|
||||
jsonObject.add(APP_VERSION, agent.getVersion().getAppVersion().toJson(false));
|
||||
}
|
||||
|
||||
return Response.ok(jsonObject.toString(), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
return Response.ok(agent.getVersion().toJson().toString(), MediaType.APPLICATION_JSON).build();
|
||||
boolean isStrolchAdmin = cert.hasRole(ROLE_STROLCH_ADMIN);
|
||||
return Response.ok(agent.getVersion().toJson(isStrolchAdmin).toString(), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue