Skip to content

Commit

Permalink
feat(jans-config-api): added patch endpoint for custom script
Browse files Browse the repository at this point in the history
  • Loading branch information
pujavs committed Apr 20, 2022
1 parent f8da77d commit e274e20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@
import java.io.IOException;
import java.util.function.Function;

import org.slf4j.Logger;

@Path(ApiConstants.CONFIG + ApiConstants.CACHE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class CacheConfigurationResource extends ConfigBaseResource {

private static final String ERROR_MSG = "Unable to apply patch.";

@Inject
Logger logger;

@Inject
ConfigurationService configurationService;

Expand Down Expand Up @@ -74,7 +69,7 @@ public Response patchCacheConfiguration(@NotNull String requestString) {
try {
return Jackson.applyPatch(requestString, cache);
} catch (IOException | JsonPatchException e) {
throw new RuntimeException(ERROR_MSG, e);
throw new InternalServerErrorException(ERROR_MSG, e);
}
});
return Response.ok(modifiedCache).build();
Expand Down Expand Up @@ -111,7 +106,7 @@ public Response patchRedisConfiguration(@NotNull String requestString) {
Jackson.applyPatch(requestString, loadCacheConfiguration().getRedisConfiguration()));
return cache;
} catch (IOException | JsonPatchException e) {
throw new RuntimeException(ERROR_MSG, e);
throw new InternalServerErrorException(ERROR_MSG, e);
}
});
return Response.ok(loadCacheConfiguration().getRedisConfiguration()).build();
Expand Down Expand Up @@ -148,7 +143,7 @@ public Response patchInMemoryConfiguration(@NotNull String requestString) {
cache.setInMemoryConfiguration(Jackson.applyPatch(requestString, cache.getInMemoryConfiguration()));
return cache;
} catch (IOException | JsonPatchException e) {
throw new RuntimeException(ERROR_MSG, e);
throw new InternalServerErrorException(ERROR_MSG, e);
}
});
return Response.ok(loadCacheConfiguration().getInMemoryConfiguration()).build();
Expand Down Expand Up @@ -187,7 +182,7 @@ public Response patchNativePersistenceConfiguration(@NotNull String requestStrin
Jackson.applyPatch(requestString, cache.getNativePersistenceConfiguration()));
return cache;
} catch (IOException | JsonPatchException e) {
throw new RuntimeException(ERROR_MSG, e);
throw new InternalServerErrorException(ERROR_MSG, e);
}
});
return Response.ok(loadCacheConfiguration().getNativePersistenceConfiguration()).build();
Expand Down Expand Up @@ -223,10 +218,10 @@ public Response patchMemcachedConfiguration(@NotNull String requestString) {
cache.setMemcachedConfiguration(Jackson.applyPatch(requestString, cache.getMemcachedConfiguration()));
return cache;
} catch (IOException | JsonPatchException e) {
throw new RuntimeException(ERROR_MSG, e);
throw new InternalServerErrorException(ERROR_MSG, e);
}
});
return Response.ok(loadCacheConfiguration().getMemcachedConfiguration()).build();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,18 @@ public Response deleteScript(@PathParam(ApiConstants.INUM) @NotNull String inum)
@Path(ApiConstants.INUM_PATH)
public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString)
throws JsonPatchException, IOException {
log.debug(" Custom Script Resource to patch - inum:{} , pathString:{}", inum, pathString);
if (log.isDebugEnabled()) {
log.debug("Custom Script Resource to patch - inum:{} , pathString:{}", escapeLog(inum),
escapeLog(pathString));
}

CustomScript existingScript = customScriptService.getScriptByInum(inum);
checkResourceNotNull(existingScript, CUSTOM_SCRIPT);
existingScript = Jackson.applyPatch(pathString, existingScript);
customScriptService.update(existingScript);
existingScript = customScriptService.getScriptByInum(inum);
log.debug(" Custom Script Resource after patch - inum:{} , pathString:{}", inum, pathString);

log.debug(" Custom Script Resource after patch - existingScript:{}", existingScript);
return Response.ok(existingScript).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import java.util.List;
Expand Down Expand Up @@ -62,6 +63,10 @@ public static void checkNotEmpty(String attribute, String attributeName) {
public static void thorwBadRequestException(String msg) {
throw new BadRequestException(getBadRequestException(msg));
}

public static void thorwInternalServerException(String msg) {
throw new InternalServerErrorException(getInternalServerException(msg));
}

/**
* @param attributeName
Expand Down

0 comments on commit e274e20

Please sign in to comment.