use of io.cdap.cdap.proto.ApplicationRecord in project cdap by caskdata.
the class AppLifecycleHttpHandler method decodeAndValidateBatchApplicationRecord.
/**
* Decodes request coming from the {@link #upgradeApplications(FullHttpRequest, HttpResponder, String, Set, boolean)}
* call.
*/
private List<ApplicationId> decodeAndValidateBatchApplicationRecord(NamespaceId namespaceId, FullHttpRequest request) throws BadRequestException {
try {
List<ApplicationId> appIds = new ArrayList<>();
List<ApplicationRecord> records = DECODE_GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), new TypeToken<List<ApplicationRecord>>() {
}.getType());
if (records == null) {
throw new BadRequestException("Request body is invalid json, please check that it is a json array.");
}
for (ApplicationRecord element : records) {
if (element.getName() != null && element.getName().isEmpty()) {
throw new BadRequestException("Missing 'name' in the request element for app-id.");
}
if (element.getAppVersion() == null) {
appIds.add(validateApplicationId(namespaceId, element.getName()));
} else {
appIds.add(validateApplicationVersionId(namespaceId, element.getName(), element.getAppVersion()));
}
}
return appIds;
} catch (JsonSyntaxException e) {
throw new BadRequestException("Request body is invalid json: " + e.getMessage());
}
}
Aggregations