Fix resource path for partial import events.

This commit is contained in:
Stan Silvert 2015-12-09 13:18:47 -05:00
parent dd038ddbd5
commit 2d878805c1
4 changed files with 35 additions and 12 deletions

View file

@ -107,14 +107,14 @@ public class PartialImportManager {
private void addedEvent(PartialImportResult result) {
adminEvent.operation(OperationType.CREATE)
.resourcePath(uriInfo)
.resourcePath(result.getResourceType().getPath(), result.getId())
.representation(result.getRepresentation())
.success();
};
private void overwrittenEvent(PartialImportResult result) {
adminEvent.operation(OperationType.UPDATE)
.resourcePath(uriInfo)
.resourcePath(result.getResourceType().getPath(), result.getId())
.representation(result.getRepresentation())
.success();
}

View file

@ -26,14 +26,14 @@ import org.codehaus.jackson.annotate.JsonIgnore;
public class PartialImportResult {
private final Action action;
private final String resourceType;
private final ResourceType resourceType;
private final String resourceName;
private final String id;
private final Object representation;
private PartialImportResult(Action action, ResourceType resourceType, String resourceName, String id, Object representation) {
this.action = action;
this.resourceType = resourceType.toString();
this.resourceType = resourceType;
this.resourceName = resourceName;
this.id = id;
this.representation = representation;
@ -55,7 +55,7 @@ public class PartialImportResult {
return action;
}
public String getResourceType() {
public ResourceType getResourceType() {
return resourceType;
}

View file

@ -24,6 +24,17 @@ package org.keycloak.partialimport;
public enum ResourceType {
USER, CLIENT, IDP, REALM_ROLE, CLIENT_ROLE;
public String getPath() {
switch(this) {
case USER: return "users";
case CLIENT: return "clients";
case IDP: return "identity-provider-settings";
case REALM_ROLE: return "realms";
case CLIENT_ROLE: return "clients";
default: return "";
}
}
@Override
public String toString() {
switch(this) {

View file

@ -123,6 +123,18 @@ public class AdminEventBuilder {
return this;
}
public AdminEventBuilder resourcePath(String... pathElements) {
StringBuilder sb = new StringBuilder();
for (String element : pathElements) {
sb.append("/");
sb.append(element);
}
if (pathElements.length > 0) sb.deleteCharAt(0); // remove leading '/'
adminEvent.setResourcePath(sb.toString());
return this;
}
public AdminEventBuilder resourcePath(UriInfo uriInfo) {
String path = getResourcePath(uriInfo);
adminEvent.setResourcePath(path);