Fix on API response messages (#50)

Co-authored-by: Thashmi-nil <nilupuleethash765@gmail.com>
Reviewed-on: community/device-mgt-core#50
Co-authored-by: Sanjana Rajapakshe <sanjana@entgra.io>
Co-committed-by: Sanjana Rajapakshe <sanjana@entgra.io>
live-chat-feature
Sanjana Rajapakshe 2 years ago committed by Pahansith Gunathilake
parent fbbd07d262
commit 4d97a6ee14

@ -402,7 +402,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
*/
private void validateRemoveAppFromFavouritesRequest(int appId) throws ApplicationManagementException {
if (!isFavouriteApp(appId)) {
String msg = "Provided appId " + appId + " is not a favourite app in order remove from favourites";
String msg = "Provided application is not a favourite app in order remove from favourites";
throw new BadRequestException(msg);
}
}
@ -417,11 +417,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
getApplication(appId);
} catch (NotFoundException e) {
String msg = " No application exists for the provided appId " + appId;
String msg = "Requested application does not exists for add to favourites.";
throw new BadRequestException(msg);
}
if (isFavouriteApp(appId)) {
String msg = "Provided appId " + appId + " is already a favourite app";
String msg = "Requested application is already in favourites list.";
throw new BadRequestException(msg);
}
}
@ -1505,7 +1505,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occured when getting, either application tags or application categories";
String msg = "Error occurred when getting, either application tags or application categories";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
@ -1779,7 +1779,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured while deleting life-cycle state data of application releases of the application"
String msg = "Error occurred while deleting life-cycle state data of application releases of the application"
+ " which has application ID: " + applicationDTO.getId();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -1896,7 +1896,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while verifying whether application relase has an subscription or "
String msg = "Error occurred while verifying whether application release has an subscription or "
+ "not. Application release UUID: " + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -1945,7 +1945,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg =
"Error occured when getting DB connection to update image artifacts of the application release "
"Error occurred when getting DB connection to update image artifacts of the application release "
+ "which has uuid " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -1957,13 +1957,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg =
"Error occured while getting application release data for updating image artifacts of the application release uuid "
"Error occurred while getting application release data for updating image artifacts of the application release uuid "
+ uuid + ".";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured while updating image artifacts of the application release uuid " + uuid + ".";
String msg = "Error occurred while updating image artifacts of the application release uuid " + uuid + ".";
log.error(msg, e);
throw new ApplicationManagementException(msg , e);
} finally {
@ -1992,7 +1992,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg);
}
} catch (DeviceManagementException e) {
String msg = "Error occured while getting supported device types in IoTS";
String msg = "Error occurred while getting supported device types in IoTS";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
@ -2034,16 +2034,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured while getting/updating APPM DB for updating application Installer.";
String msg = "Error occurred while getting/updating APPM DB for updating application Installer.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occured while starting the transaction to update application release artifact which has "
String msg = "Error occurred while starting the transaction to update application release artifact which has "
+ "application uuid " + releaseUuid + ".";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occured when getting DB connection to update application release artifact of the "
String msg = "Error occurred when getting DB connection to update application release artifact of the "
+ "application release uuid " + releaseUuid + ".";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -2054,7 +2054,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating application installer.";
String msg = "Error occurred when updating application installer.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
@ -2252,7 +2252,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when getting existing categories or when inserting new application categories.";
String msg = "Error occurred when getting existing categories or when inserting new application categories.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
@ -2574,7 +2574,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDAO.deleteApplicationTag(tag.getId(), applicationDTO.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction();
} else {
String msg = "Tag " + tagName + " is not an application tag. Application ID: " + appId;
String msg = "Tag " + tagName + " is not an application tag. Application name: " + applicationDTO.getName();
log.error(msg);
throw new BadRequestException(msg);
}
@ -2782,7 +2782,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
.collect(Collectors.toList());
} else {
String msg = "Tag list is either null or empty. In order to add new tags for application which has "
+ "application ID: " + appId +", tag list should be a list of Stings. Therefore please "
+ "application name: " + applicationDTO.getName() +", tag list should be a list of Stings. Therefore please "
+ "verify the payload.";
log.error(msg);
throw new BadRequestException(msg);
@ -2888,11 +2888,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public void updateCategory(String oldCategoryName, String newCategoryName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (StringUtils.isEmpty(oldCategoryName) || StringUtils.isEmpty(newCategoryName)) {
String msg = "Either old category name or new category name contains empty/null value. Hence please verify the "
+ "request.";
log.error(msg);
throw new BadRequestException(msg);
}
try {
ConnectionManagerUtil.beginDBTransaction();
CategoryDTO category = applicationDAO.getCategoryForCategoryName(oldCategoryName, tenantId);
if (category == null){
String msg = "Couldn't found a category for tag name " + oldCategoryName + ".";
String msg = "Couldn't found a category for category name " + oldCategoryName + ".";
log.error(msg);
throw new NotFoundException(msg);
}
@ -2904,7 +2910,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Database access error is occurred when updating categiry.";
String msg = "Database access error is occurred when updating category.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
@ -3079,11 +3085,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid;
String msg = "Error occurred when updating Ent Application release of UUID: " + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
String msg = "Error occured when updating application release artifact in the file system. Ent App release "
String msg = "Error occurred when updating application release artifact in the file system. Ent App release "
+ "UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -3148,11 +3154,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating public app release of UUID: " + releaseUuid;
String msg = "Error occurred when updating public app release of UUID: " + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
String msg = "Error occured when updating public app release artifact in the file system. Public app "
String msg = "Error occurred when updating public app release artifact in the file system. Public app "
+ "release UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -3213,11 +3219,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating web app release for web app Release UUID: " + releaseUuid;
String msg = "Error occurred when updating web app release for web app Release UUID: " + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
String msg = "Error occured when updating web app release artifact in the file system. Web app "
String msg = "Error occurred when updating web app release artifact in the file system. Web app "
+ "release UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -3343,11 +3349,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid;
String msg = "Error occurred when updating Ent Application release of UUID: " + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ResourceManagementException e) {
String msg = "Error occured when updating application release artifact in the file system. Ent App release "
String msg = "Error occurred when updating application release artifact in the file system. Ent App release "
+ "UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -3721,7 +3727,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg);
}
if (StringUtils.isEmpty(webAppReleaseWrapper.getUrl())) {
String msg = "URL should't be null for the application release creating request for application type "
String msg = "URL shouldn't be null for the application release creating request for application type "
+ "WEB_CLIP";
log.error(msg);
throw new BadRequestException(msg);
@ -3901,11 +3907,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
String msg = "Error occured while updating app subscription status of the device.";
String msg = "Error occurred while updating app subscription status of the device.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while obersving the database connection to update aoo subscription status of "
String msg = "Error occurred while observing the database connection to update aoo subscription status of "
+ "device.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -3932,11 +3938,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
String msg = "Error occured while updating app subscription status of the device.";
String msg = "Error occurred while updating app subscription status of the device.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while obersving the database connection to update aoo subscription status of "
String msg = "Error occurred while observing the database connection to update aoo subscription status of "
+ "device.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);

@ -224,7 +224,7 @@ public class ReviewManagerImpl implements ReviewManager {
throw new ReviewManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured while verifying whether application release is exists or not for UUID " + uuid;
String msg = "Error occurred while verifying whether application release is exists or not for UUID " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} finally {
@ -360,7 +360,7 @@ public class ReviewManagerImpl implements ReviewManager {
return null;
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured while getting reviewTmp with reviewTmp id " + reviewId + ".";
String msg = "Error occurred while getting reviewTmp with reviewTmp id " + reviewId + ".";
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (DBConnectionException e) {
@ -393,11 +393,11 @@ public class ReviewManagerImpl implements ReviewManager {
}
return getReviewTree(this.reviewDAO.getAllReleaseReviews(releaseDTO.getId(), request, tenantId));
} catch (ReviewManagementDAOException e) {
String msg = "Error occured while getting all reviews for application uuid: " + uuid;
String msg = "Error occurred while getting all reviews for application uuid: " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (DBConnectionException e) {
String msg ="Error occured while getting the DB connection to get all reviews for application release which"
String msg ="Error occurred while getting the DB connection to get all reviews for application release which"
+ " has UUID " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
@ -423,12 +423,12 @@ public class ReviewManagerImpl implements ReviewManager {
ConnectionManagerUtil.openDBConnection();
return getReviewTree(this.reviewDAO.getAllActiveAppReviews(applicationReleaseIds, request, tenantId));
} catch (ReviewManagementDAOException e) {
String msg = "Error occured while getting all reviews for application which has an "
String msg = "Error occurred while getting all reviews for application which has an "
+ "application release of uuid: " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occured while getting the DB connection to get app app reviews.";
String msg = "Error occurred while getting the DB connection to get app app reviews.";
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} finally {
@ -458,12 +458,12 @@ public class ReviewManagerImpl implements ReviewManager {
}
return getReviewTree(reviewDtos);
} catch (ReviewManagementDAOException e) {
String msg = "Error occured while getting all " + username + "'s reviews for application which has an "
String msg = "Error occurred while getting all " + username + "'s reviews for application which has an "
+ "application release of uuid: " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occured while getting DB connection to get all " + username + "'s reviews for "
String msg = "Error occurred while getting DB connection to get all " + username + "'s reviews for "
+ "application which has an application release of uuid: " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
@ -486,7 +486,7 @@ public class ReviewManagerImpl implements ReviewManager {
.collect(Collectors.toList());
} catch (DBConnectionException e) {
String msg =
"Error occured while getting the DB connection to get application which has application release"
"Error occurred while getting the DB connection to get application which has application release"
+ " of UUID: " + uuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
@ -526,7 +526,7 @@ public class ReviewManagerImpl implements ReviewManager {
paginationResult.setRecordsTotal(numOfReviews);
return paginationResult;
} catch (ReviewManagementDAOException e) {
String msg = "Error occured while getting all reply comments for given review list";
String msg = "Error occurred while getting all reply comments for given review list";
log.error(msg, e);
throw new ReviewManagementException(msg, e);
}
@ -635,11 +635,11 @@ public class ReviewManagerImpl implements ReviewManager {
throw new ReviewManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occured while deleting review with review id " + reviewId + ".";
String msg = "Error occurred while deleting review with review id " + reviewId + ".";
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred when handleing transaction to delete application reviews.";
String msg = "Error occurred when handling transaction to delete application reviews.";
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} finally {
@ -663,16 +663,16 @@ public class ReviewManagerImpl implements ReviewManager {
return rating;
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occured while getting the rating value of the application release uuid: " + appReleaseUuid;
"Error occurred while getting the rating value of the application release uuid: " + appReleaseUuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occured while getting the rating value of the application release uuid: "
String msg = "DB Connection error occurred while getting the rating value of the application release uuid: "
+ appReleaseUuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
String msg = "Error occured while getting all rating values for the application release UUID: "
String msg = "Error occurred while getting all rating values for the application release UUID: "
+ appReleaseUuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
@ -704,18 +704,18 @@ public class ReviewManagerImpl implements ReviewManager {
return rating;
} catch (DBConnectionException e) {
String msg =
"DB Connection error occured while getting app rating of the application which has application "
"DB Connection error occurred while getting app rating of the application which has application "
+ "release for uuid: " + appReleaseUuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occured while getting the application DTO for the application release uuid: "
String msg = "Error occurred while getting the application DTO for the application release uuid: "
+ appReleaseUuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
String msg =
"Error occured while getting all rating values of application which has the application release "
"Error occurred while getting all rating values of application which has the application release "
+ "for UUID: " + appReleaseUuid;
log.error(msg, e);
throw new ReviewManagementException(msg, e);

@ -367,14 +367,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try {
device = DataHolder.getInstance().getDeviceManagementService().getDevice(deviceIdentifier, false);
if (device == null) {
String msg = "Invalid device identifier is received and couldn't find an deveice for the requested "
String msg = "Invalid device identifier is received and couldn't find an device for the requested "
+ "device identifier. Device UUID: " + deviceIdentifier.getId() + " Device Type: "
+ deviceIdentifier.getType();
log.error(msg);
throw new BadRequestException(msg);
}
} catch (DeviceManagementException e) {
String msg = "Error occured while getting device data for given device identifier.Device UUID: "
String msg = "Error occurred while getting device data for given device identifier.Device UUID: "
+ deviceIdentifier.getId() + " Device Type: " + deviceIdentifier.getType();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);

@ -89,11 +89,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationList applications = applicationManager.getApplications(filter);
return Response.status(Response.Status.OK).entity(applications).build();
} catch (BadRequestException e) {
String msg = "Incompatible request payload is found. Please try with valid request payload.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (UnexpectedServerErrorException e) {
String msg = "Error Occured when getting supported device types by Entgra IoTS";
String msg = "Error occurred when getting supported device types by Entgra IoTS";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -173,7 +173,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
try {
return createApplication(applicationWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with ent. app creating request.";
String msg = "Found incompatible payload with ent. app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -195,7 +195,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
try {
return createApplication(webAppWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with web app creating request.";
String msg = "Found incompatible payload with web app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -217,7 +217,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
try {
return createApplication(publicAppWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with pub app creating request.";
String msg = "Found incompatible payload with pub app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -239,7 +239,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
try {
return createApplication(customAppWrapper, isPublished);
} catch (BadRequestException e) {
String msg = "Found incompatible payload with custom app creating request.";
String msg = "Found incompatible payload with custom app creating request. Please try with valid request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -267,7 +267,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(release).build();
} catch (RequestValidatingException e) {
String msg = "Error occurred while validating binaryArtifact";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e){
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -291,6 +295,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationManager.validatePublicAppReleaseCreatingRequest(publicAppReleaseWrapper, deviceTypeName);
ApplicationRelease applicationRelease = applicationManager.createPubAppRelease(appId, publicAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e);
@ -300,7 +308,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Invalid payload found in public app release create request";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
@ -318,6 +326,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper);
ApplicationRelease applicationRelease= applicationManager.createWebAppRelease(appId, webAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts";
log.error(msg, e);
@ -327,7 +339,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Invalid payload found in web app release create request";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
@ -346,8 +358,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName);
ApplicationRelease release = applicationManager.createCustomAppRelease(appId, customAppReleaseWrapper, isPublished);
return Response.status(Response.Status.CREATED).entity(release).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Error occurred while validating binaryArtifact";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ResourceManagementException e) {
@ -386,7 +402,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String msg = "Found invalid device type to check application existence.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -460,6 +476,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
String msg = "Found an invalid device type: " + deviceType + " with the request";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while updating the image artifacts of the application with the uuid "
+ applicationReleaseUuid;
@ -483,8 +503,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Error occurred while modifying the application. Found bad request payload for updating the "
+ "application";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -514,8 +533,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update ent app release for application release UUID " + applicationUUID;
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
@ -555,7 +573,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = "Invalid request to update public app release for application release UUID " + applicationUUID;
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
@ -595,7 +613,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID;
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
@ -634,8 +652,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update ent app release for application release UUID " + applicationUUID;
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
@ -685,7 +702,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
.changeLifecycleState(applicationUuid, lifecycleChanger);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = "Request payload contains invalid data, hence verify the request payload.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (ForbiddenException e) {
@ -847,6 +864,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
try {
List<String> applicationTags = applicationManager.addApplicationTags(appId, tagNames);
return Response.status(Response.Status.OK).entity(applicationTags).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);

@ -96,6 +96,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String msg = "Identity server with the id " + id + " does not exist.";
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
@ -115,6 +116,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String msg = "Identity server with the id " + id + " does not exist.";
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
@ -134,9 +136,10 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String msg = "Identity server with the id " + id + " does not exist.";
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String errMsg = "Identity server request payload is invalid";
String errMsg = e.getMessage();
log.error(errMsg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
@ -156,7 +159,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
IdentityServerResponse identityServer = spAppManager.createIdentityServer(identityServerDTO);
return Response.status(Response.Status.CREATED).entity(identityServer).build();
} catch (BadRequestException e) {
String errMsg = "Identity server request payload is invalid";
String errMsg = e.getMessage();
log.error(errMsg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
@ -232,6 +235,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String errMsg = "No Identity server exist with the id: " + identityServerId;
log.error(errMsg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} catch (ApplicationManagementException e) {
String errMsg = "Error occurred while trying to merge identity server apps with existing apps";
@ -252,6 +256,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String msg = "No identity server exist with the id " + identityServerId;
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid appIds provided";
@ -277,6 +282,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String msg = "No identity server exist with the id " + identityServerId;
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid appIds provided";
@ -343,6 +349,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} catch (NotFoundException e) {
String msg = "No identity server exist with the id " + identityServerId;
log.error(msg, e);
// TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found incompatible payload with create service provider app request.";

@ -155,6 +155,10 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
applicationManager.updateCategory(oldCategoryName, newCategoryName);
return Response.status(Response.Status.OK)
.entity("Category is updated from " + oldCategoryName + " to " + newCategoryName).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg = e.getMessage();
log.error(msg, e);
@ -181,6 +185,10 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error Occurred while deleting registered category.";
log.error(msg, e);

@ -58,7 +58,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
applicationManager.addAppToFavourites(appId);
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String msg = "Invalid payload found in the request. Hence verify the request payload.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -78,7 +78,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
applicationManager.removeAppFromFavourites(appId);
return Response.status(Response.Status.OK).build();
} catch (BadRequestException e) {
String msg = "Invalid payload found in the request. Hence verify the request payload.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -147,7 +147,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
String msg = "Could not found an application release which is in " + applicationManager
.getInstallableLifecycleState() + " state.";
log.error(msg);
return Response.status(Response.Status.OK).entity(msg).build();
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) {

@ -131,7 +131,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload data with the request. Hence, please verify the request payload.";
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -144,7 +144,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occured while accessing application release for UUID: " + uuid;
String msg = "Error occurred while accessing application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -164,7 +164,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
if (isRepliedForReview) {
return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else {
String msg = "Error occured when adding reply comment for the review. Please contact the administrator..";
String msg = "Error occurred when adding reply comment for the review. Please contact the administrator..";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -173,7 +173,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload data with the request to add reply comment. Hence, please verify the "
String msg = "Invalid payload data found with the requested add reply comment. Hence, please verify the "
+ "request payload.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
@ -182,7 +182,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occured while accessing application release for UUID: " + uuid;
String msg = "Error occurred while accessing application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -214,8 +214,12 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
String msg = "Couldn't found application release data for UUID " + uuid + " or Review for review ID: " + reviewId;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid payload data found with the request. Hence, please verify the request payload.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You dont have permission to update application release review.";
String msg = "You don't have permission to update application release review.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
@ -267,7 +271,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException | ApplicationManagementException e) {
String msg = "Error occured while getting review data for application release UUID: " + uuid;
String msg = "Error occurred while getting review data for application release UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}

@ -93,12 +93,11 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
SubAction.valueOf(action.toUpperCase()), timestamp, properties);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUI: " + uuid;
String msg = "Couldn't found an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify "
+ "the payload";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -147,8 +146,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify "
+ "the payload";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -187,13 +185,12 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUI: " + uuid + " to perform ent app installation "
String msg = "Couldn't found an application release for UUID: " + uuid + " to perform ent app installation "
+ "on subscriber's devices";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload when performing ent app installation on application which has UUID: "
+ uuid + ". Hence verify the payload of the request.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -237,8 +234,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload when performing ent app installation on application which has UUID: "
+ uuid + ". Hence verify the payload of the request.";
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -360,7 +356,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "User requested details are not valid";
String msg = "User requested details are not valid. Please verify the payload of the request.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -424,8 +420,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload for getting application which has UUID: " + uuid
+ ". Hence verify the payload";
String msg = "Invalid payload found when getting application. Hence verify the payload";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
@ -502,6 +497,10 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
String msg = "Application with application release UUID: " + uuid + " is not found";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Invalid payload found with the request. Please verify the payload.";
log.error(msg,e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting application with the application " +
"release uuid: " + uuid;

@ -133,7 +133,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "User requested details are not valid";
String msg = "User requested details are not valid. Please verify the request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {

@ -91,9 +91,7 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig
if (properties == null || properties.isEmpty()) {
String msg = "Devices configuration retrieval criteria cannot be null or empty.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()
).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ObjectMapper mapper = new ObjectMapper();
@ -113,18 +111,15 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (DeviceNotFoundException e) {
log.warn(e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (AmbiguousConfigurationException e) {
String msg = "Configurations are ambiguous. " + e.getMessage();
log.warn(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (JsonParseException | JsonMappingException e) {
String msg = "Malformed device property structure";
log.error(msg.concat(" ").concat(properties), e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (IOException e) {
String msg = "Error occurred while parsing query param JSON data.";
log.error(msg.concat(" ").concat(properties), e);
@ -150,8 +145,7 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig
if (devicesTransferred.isEmpty()) {
String msg = "Devices are not enrolled to super tenant";
log.warn(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} else {
return Response.status(Response.Status.OK).entity(devicesTransferred).build();
}
@ -163,8 +157,7 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (DeviceNotFoundException e) {
log.error(e.getMessage(), e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}

@ -74,9 +74,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activity = dmService.getOperationByActivityId(id);
if (activity == null) {
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " +
"found upon the provided activity id '" + id + "'").build()).build();
String msg = "No activity can be " +
"found upon the provided activity id '" + id + "'";
return Response.status(404).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(activity).build();
} catch (OperationManagementException e) {
@ -98,10 +98,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
List<String> idList;
idList = activityIdList.getIdList();
if (idList == null || idList.isEmpty()) {
String msg = "Activity Ids shouldn't be empty";
String msg = "Activities should not be empty";
log.error(msg);
return Response.status(400).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(400).entity(msg).build();
}
Response validationFailedResponse = validateAdminPermission();
if (validationFailedResponse == null) {
@ -125,8 +124,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
} else {
String msg = "No activity found with the given IDs.";
log.error(msg);
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(404).entity(msg).build();
}
} catch (OperationManagementException e) {
String msg = "ErrorResponse occurred while fetching the activity list for the supplied ids.";
@ -162,9 +160,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier);
if (activity == null) {
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " +
"found upon the provided activity id '" + id + "'").build()).build();
String msg = "No activity can be " +
"found upon the provided activity id '" + id + "'";
return Response.status(404).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(activity).build();
} catch (OperationManagementException e) {
@ -247,9 +245,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
try {
ifSinceDate = format.parse(ifModifiedSince);
} catch (ParseException e) {
return Response.status(400).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"Invalid date string is provided in 'If-Modified-Since' header").build()).build();
String msg = "Invalid date string is provided in [If-Modified-Since] header.";
return Response.status(400).entity(msg).build();
}
ifModifiedSinceTimestamp = ifSinceDate.getTime();
timestamp = ifModifiedSinceTimestamp / 1000;
@ -259,9 +256,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
try {
sinceDate = format.parse(since);
} catch (ParseException e) {
return Response.status(400).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"Invalid date string is provided in 'since' filter").build()).build();
String msg = "Invalid date string is provided in [since] filter.";
return Response.status(400).entity(msg).build();
}
sinceTimestamp = sinceDate.getTime();
timestamp = sinceTimestamp / 1000;

@ -169,10 +169,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("limit") int limit) {
try {
if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(role)) {
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Request contains both name and role " +
"parameters. Only one is allowed " +
"at once.").build()).build();
String msg = "Request contains both name and role parameters. Only one is allowed at once.";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
// RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status);
RequestValidationUtil.validatePaginationParameters(offset, limit);
@ -261,9 +259,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
try {
sinceDate = format.parse(ifModifiedSince);
} catch (ParseException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
"string is provided in 'If-Modified-Since' header").build()).build();
String msg = "Invalid date string is provided in [If-Modified-Since] header";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
request.setSince(sinceDate);
if (requireDeviceInfo) {
@ -282,9 +279,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
try {
sinceDate = format.parse(since);
} catch (ParseException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
"string is provided in 'since' filter").build()).build();
String msg = "Invalid date string is provided in [since] filter";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
request.setSince(sinceDate);
if (requireDeviceInfo) {
@ -517,6 +513,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String msg = "Error occurred while retrieving role list of user '" + authorizedUser + "'";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}catch (BadRequestException e){
String msg = "Error occurred while validating the device group.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
PaginationResult result = dms.getAllDevices(request, false);
@ -533,7 +533,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
}
return Response.status(Response.Status.OK).entity(devices).build();
} catch (BadRequestException e) {
String msg = "Invalid type, use either 'path' or 'full'";
String msg = "Invalid type, use either [path] or [full]";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (UnAuthorizedException e) {
@ -567,12 +567,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
boolean response = deviceManagementProviderService.disenrollDevice(deviceIdentifier);
return Response.status(Response.Status.OK).entity(response).build();
} catch (DeviceManagementException e) {
String msg = "Error encountered while deleting device of type : " + deviceType + " and " +
"ID : " + deviceId;
String msg = "Error encountered while deleting requested device of type : " + deviceType ;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()
).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -594,11 +591,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.CREATED).entity(response).build();
} catch (DeviceManagementException e) {
log.error("Error encountered while updating device of type : " + deviceType + " and " +
"ID : " + deviceId);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error while updating " +
"device of type " + deviceType + " and ID : " + deviceId).build()).build();
String msg = "Error encountered while updating requested device of type : " + deviceType ;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -639,10 +634,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
sinceDate = format.parse(ifModifiedSince);
deviceData.setLastModifiedDate(sinceDate);
} catch (ParseException e) {
String msg = "Invalid date string is provided in 'If-Modified-Since' header";
String msg = "Invalid date string is provided in [If-Modified-Since] header";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -669,9 +663,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
"after the timestamp provided in 'If-Modified-Since' header").build();
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_NOT_FOUND).setMessage("Requested device of type '" +
type + "', which carries id '" + id + "' does not exist").build()).build();
String msg = "Requested device of type " + type + " does not exist";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(device).build();
}
@ -692,7 +685,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
dms);
return Response.status(Response.Status.OK).entity(snapshotWrapper).build();
} catch (BadRequestException e) {
String msg = "Invalid type, use either 'path' or 'full'";
String msg = "Invalid type, use either [path] or [full]";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (UnAuthorizedException e) {
@ -738,12 +731,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
try {
sinceDate = format.parse(ifModifiedSince);
} catch (ParseException e) {
String message = "Error occurred while parse the since date.Invalid date string is provided in " +
"'If-Modified-Since' header";
String message = "Invalid date string is provided in [If-Modified-Since] header";
log.error(message, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
"string is provided in 'If-Modified-Since' header").build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
if (sinceDate != null) {
@ -752,16 +742,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String message = "No device is modified after the timestamp provided in 'If-Modified-Since' header";
log.error(message);
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
"after the timestamp provided in 'If-Modified-Since' header").build();
"after the timestamp provided in [If-Modified-Since] header").build();
}
} else {
device = dms.getDevice(id, requireDeviceInfo);
}
if (device == null) {
String message = "Device does not exist with id '" + id + "'";
String message = "Device does not exist";
log.error(message);
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(message).build()).build();
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, device.getType());
// check whether the user is authorized
@ -819,7 +808,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceManagementProviderService deviceManagementProviderService =
DeviceMgtAPIUtils.getDeviceManagementService();
if (deviceIds == null || deviceIds.isEmpty()) {
String msg = "Required values of device identifiers are not set..";
String msg = "Required values of device identifiers are not set.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build();
}
@ -1000,9 +989,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
try {
fm = dms.getFeatureManager(type);
} catch (DeviceTypeNotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder()
.setMessage("No device type found with name '" + type + "'").build()).build();
String msg = "No device type found with name : " + type ;
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
if (fm != null) {
features = fm.getFeatures();
@ -1223,8 +1211,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (InputValidationException e) {
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
"carries the id '" + id + "'";
String msg = "Error occurred while fetching the operations for the type : " + type + " device";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (DeviceManagementException e) {
@ -1233,7 +1220,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (DeviceTypeNotFoundException e) {
String msg = "No device type found with name '" + type + "'";
String msg = "No device type found with name : " + type ;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
@ -1343,11 +1330,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus);
return Response.status(Response.Status.OK).entity(response).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while changing device status of type : " + type + " and " +
"device id : " + id;
String msg = "Error occurred while changing device status of device type : " + type ;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -1375,11 +1360,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
List<DeviceStatus> deviceStatusHistory = deviceManagementProviderService.getDeviceStatusHistory(persistedDevice);
return Response.status(Response.Status.OK).entity(deviceStatusHistory).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while retreiving device status history for device of type : " + type + " and " +
"device id : " + id;
String msg = "Error occurred while retrieving device status history for device of type : " + type ;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -1407,11 +1390,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
List<DeviceStatus> deviceStatusHistory = deviceManagementProviderService.getDeviceCurrentEnrolmentStatusHistory(persistedDevice);
return Response.status(Response.Status.OK).entity(deviceStatusHistory).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while retreiving device status history for device of type : " + type + " and " +
"device id : " + id;
String msg = "Error occurred while retrieving device status history for device of type : " + type;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -1488,7 +1469,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (DeviceManagementException e) {
String errorMessage = "Issue in retrieving deivce management service instance";
String errorMessage = "Issue in retrieving device management service instance";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
@ -1688,7 +1669,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType(
deviceType, tenantId);
if (deviceTypeObj == null) {
String msg = "Error, device of type: " + deviceType + " does not exist";
String msg = "Device of type: " + deviceType + " does not exist";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}

@ -141,16 +141,15 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
DeviceManagementProviderService dms;
try {
if (StringUtils.isEmpty(type)) {
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Type cannot be empty.").build()).build();
String msg = "Type cannot be empty.";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
dms = DeviceMgtAPIUtils.getDeviceManagementService();
FeatureManager fm = dms.getFeatureManager(type);
if (fm == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
"registered with the given type '" + type + "'").build()).build();
String msg = "No feature manager is registered with the given type : " + type ;
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
if (StringUtils.isEmpty(hidden)) {
@ -165,11 +164,9 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (DeviceTypeNotFoundException e) {
String msg = "No device type found with name '" + type + "'";
String msg = "No device type found with name : " + type ;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder()
.setMessage(msg).build()).build();
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(features).build();
}

@ -63,6 +63,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.EventAction;
import org.wso2.carbon.device.mgt.jaxrs.beans.GeofenceWrapper;
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
@ -107,8 +108,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@QueryParam("from") long from, @QueryParam("to") long to) {
try {
if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) {
String msg = "Unable to retrieve Geo Device stats. Geo Data publishing does not enabled.";
return Response.status(Response.Status.BAD_REQUEST.getStatusCode())
.entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build();
.entity(msg).build();
}
} catch (DeviceManagementException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(e.getMessage()).build();
@ -277,7 +279,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (log.isDebugEnabled()) {
log.debug("Device not found: " + identifier.toString());
}
return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build();
String msg = "Device not found.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
@ -288,12 +291,11 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
} catch (AlertAlreadyExistException e) {
String error = "A geo alert with this name already exists.";
String error = "A geo alert with this name already exists. Try with another name.";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
} catch (DeviceManagementException e) {
String error = "Error occurred while retrieving the device enrollment info of " +
deviceType + " with id: " + deviceId;
String error = "Error occurred while retrieving the device enrollment info of requested "+ deviceType + " device.";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
@ -314,7 +316,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
} catch (AlertAlreadyExistException e) {
String error = "A geo alert with this name already exists.";
String error = "A geo alert with this name already exists. Try with another name.";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
@ -344,23 +346,23 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (log.isDebugEnabled()) {
log.debug("Device not found: " + identifier.toString());
}
return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build();
String msg = "Device not found.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
geoService.updateGeoAlert(alert, identifier, alertType, device.getEnrolmentInfo().getOwner());
return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException e) {
String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId;
String error = "Error occurred while updating the geo alert for " + deviceType + " with id: " + deviceId;
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
} catch (AlertAlreadyExistException e) {
String error = "A geo alert with this name already exists.";
String error = "A geo alert with this name already exists. Try with another name.";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
} catch (DeviceManagementException e) {
String error = "Error occurred while retrieving the device enrollment info of " +
deviceType + " with id: " + deviceId;
String error = "Error occurred while retrieving the device enrollment info of requested " + deviceType + " device.";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
@ -380,7 +382,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
} catch (AlertAlreadyExistException e) {
String error = "A geo alert with this name already exists.";
String error = "A geo alert with this name already exists. Try with another name.";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
@ -410,7 +412,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (log.isDebugEnabled()) {
log.debug("Device not found: " + identifier.toString());
}
return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build();
String msg = "Device not found.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
@ -421,8 +424,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
} catch (DeviceManagementException e) {
String error = "Error occurred while retrieving the device enrollment info of " +
deviceType + " with id: " + deviceId;
String error = "Error occurred while retrieving the device enrollment info of requested " +deviceType + " device";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
@ -467,7 +469,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (log.isDebugEnabled()) {
log.debug("Device not found: " + identifier.toString());
}
return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build();
String msg = "Device not found.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
@ -497,8 +500,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
} catch (DeviceManagementException e) {
String error = "Error occurred while retrieving the device enrollment info of " +
deviceType + " with id: " + deviceId;
String error = "Error occurred while retrieving the device enrollment info of requested " + deviceType + " device";
log.error(error, e);
return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
}
@ -687,9 +689,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@Consumes("application/json")
@Produces("application/json")
public Response createGeofence(GeofenceWrapper geofenceWrapper) {
try {
RequestValidationUtil.validateGeofenceData(geofenceWrapper);
RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig());
try {
GeofenceData geofenceData = mapRequestGeofenceData(geofenceWrapper);
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
if (!geoService.createGeofence(geofenceData)) {
@ -699,6 +701,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(Response.Status.CREATED).entity("Geo Fence record created successfully").build();
} catch (BadRequestException e){
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (GeoLocationBasedServiceException e) {
String msg = "Failed to create geofence";
log.error(msg, e);
@ -895,9 +899,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
public Response updateGeofence(GeofenceWrapper geofenceWrapper,
@PathParam("fenceId") int fenceId,
@QueryParam("eventIds") int[] eventIds) {
try {
RequestValidationUtil.validateGeofenceData(geofenceWrapper);
RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig());
try {
GeofenceData geofenceData = mapRequestGeofenceData(geofenceWrapper);
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
if (!geoService.updateGeofence(geofenceData, fenceId)) {
@ -912,6 +916,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
geoService.updateGeoEventConfigurations(geofenceData, eventsToRemove,
geofenceData.getGroupIds(), fenceId);
return Response.status(Response.Status.CREATED).entity("Geo Fence update successfully").build();
} catch (BadRequestException e){
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (GeoLocationBasedServiceException e) {
String msg = "Failed to update geofence";
log.error(msg, e);

@ -167,7 +167,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupAlreadyExistException e) {
String msg = "Group already exists with name " + group.getName() + ".";
String msg = "Group already exists with name : " + group.getName() + ".";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
@ -181,7 +181,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
if (deviceGroup != null) {
return Response.status(Response.Status.OK).entity(deviceGroup).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
return Response.status(Response.Status.NOT_FOUND).entity("Group not found.").build();
}
} catch (GroupManagementException e) {
String error = "Error occurred while getting the group.";
@ -198,7 +198,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
if (deviceGroup != null) {
return Response.status(Response.Status.OK).entity(deviceGroup).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
return Response.status(Response.Status.NOT_FOUND).entity("Group not found.").build();
}
} catch (GroupManagementException e) {
String error = "Error occurred while getting the group.";
@ -220,11 +220,11 @@ public class GroupManagementServiceImpl implements GroupManagementService {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupNotExistException e) {
String msg = "Group doesn't exist with ID '" + deviceGroup.getGroupId() + "'.";
String msg = "Group does not exist.";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
} catch (GroupAlreadyExistException e) {
String msg = "Group already exists with name '" + deviceGroup.getName() + "'.";
String msg = "Group already exists with name : '" + deviceGroup.getName() + "'.";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}

@ -83,8 +83,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
.validatePolicyDetails(policyWrapper);
// validation failure results;
if (!features.isEmpty()) {
log.error("Policy feature/s validation failed.");
return Response.status(Response.Status.BAD_REQUEST).entity(features).build();
String msg = "Policy feature/s validation failed." ;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg + " Features : " + features).build();
}
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
@ -212,9 +213,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policy = policyAdministratorPoint.getPolicy(id);
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"No policy found with the id '" + id + "'").build()).build();
String msg = "Policy not found.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
} catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving policy corresponding to the id '" + id + "'";
@ -233,8 +233,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
.validatePolicyDetails(policyWrapper);
// validation failure results;
if (!features.isEmpty()) {
log.error("Policy feature/s validation failed.");
return Response.status(Response.Status.BAD_REQUEST).entity(features).build();
String msg = "Policy feature/s validation failed." ;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg + " Features : " + features).build();
}
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
try {
@ -296,10 +297,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
//TODO:Check of this logic is correct
String modifiedInvalidPolicyIds =
invalidPolicyIds.substring(0, invalidPolicyIds.length() - 1);
return Response.status(Response.Status.BAD_REQUEST).
entity(new ErrorResponse.ErrorResponseBuilder().
setMessage("Policies with the policy ID " + modifiedInvalidPolicyIds +
" doesn't exist").build()).build();
String msg = "Policies does not exist.";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -329,9 +328,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
return Response.status(Response.Status.OK).entity("Selected policies have been successfully activated")
.build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " +
"not been activated").build()).build();
String msg = "Selected policies have not been activated.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
}
@ -361,9 +359,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
return Response.status(Response.Status.OK).entity("Selected policies have been successfully " +
"deactivated").build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " +
"not been deactivated").build()).build();
String msg = "Selected policies have not been activated.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
}
@ -412,9 +409,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
+ "updated.").build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy priorities did "
+ "not update. Bad Request.").build()).build();
String msg = "Policy priorities did not update. Bad Request.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
}
@ -440,9 +436,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
}
policy = policyManagementService.getAppliedPolicyToDevice(device);
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"No policy found for device ID '" + deviceId + "'"+ deviceId).build()).build();
String msg = "Policy not found for the requested device.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
} catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving policy corresponding to the id '" + deviceType + "'"+ deviceId;
@ -491,8 +486,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
= RequestValidationUtil.validateProfileFeatures(profileFeaturesList);
// validation failure results;
if (!features.isEmpty()) {
log.error("Policy feature/s validation failed.");
return Response.status(Response.Status.BAD_REQUEST).entity(features).build();
String msg = "Policy feature/s validation failed." ;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg + " Features : " +features).build();
}
return Response.status(Response.Status.OK).entity("Valid request").build();

@ -169,8 +169,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
try {
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
if (!userRealm.getUserStoreManager().isExistingRole(roleName)) {
return Response.status(404).entity(new ErrorResponse.ErrorResponseBuilder().setMessage(
"No role exists with the name '" + roleName + "'").build()).build();
String msg = "No role exists with the name : " + roleName ;
return Response.status(404).entity(msg).build();
}
final UIPermissionNode rolePermissions = this.getUIPermissionNode(roleName, userRealm);
@ -249,9 +250,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
if (!userStoreManager.isExistingRole(roleName)) {
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
roleName + "'").build()).build();
String msg = "No role exists with the name : " + roleName ;
return Response.status(404).entity(msg).build();
}
roleInfo.setRoleName(roleName);
roleInfo.setUsers(userStoreManager.getUserListOfRole(roleName));
@ -325,7 +325,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
}
if (ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode().equals(errorCode)) {
String roleName = roleInfo.getRoleName().split("/")[1];
String msg = "Role already exists with name " + roleName + ".";
String msg = "Role already exists with name : " + roleName + ". Try with another role name.";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
} else {
@ -354,10 +354,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
roleName = userStoreName + "/" + roleName;
}
if (roles.size() < 2) {
return Response.status(400).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Combining Roles requires at least two roles.")
.build()
).build();
String msg = "Combining Roles requires at least two roles.";
return Response.status(400).entity(msg).build();
}
for (String role : roles) {
RequestValidationUtil.validateRoleName(role);
@ -374,9 +372,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
mergePermissions(new UIPermissionNode[]{getRolePermissions(role)}, permsSet);
}
} catch (IllegalArgumentException e) {
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()
).build();
return Response.status(404).entity(e.getMessage()).build();
}
Permission[] permissions = permsSet.toArray(new Permission[permsSet.size()]);
@ -424,9 +420,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
if (!userStoreManager.isExistingRole(roleName)) {
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
roleName + "'").build()).build();
String msg = "No role exists with the name : " + roleName ;
return Response.status(404).entity(msg).build();
}
final AuthorizationManager authorizationManager = userRealm.getAuthorizationManager();
@ -481,10 +476,23 @@ public class RoleManagementServiceImpl implements RoleManagementService {
return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " +
"successfully been updated").build();
} catch (UserStoreException e) {
String errorCode = "";
String errorMessage = e.getMessage();
if (errorMessage != null && !errorMessage.isEmpty() &&
errorMessage.contains(ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode())) {
errorCode = e.getMessage().split("-")[0].trim();
}
if (ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode().equals(errorCode)) {
String role = roleInfo.getRoleName().split("/")[1];
String msg = "Role already exists with name : " + role + ". Try with another role name.";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}else{
String msg = "Error occurred while updating role '" + roleName + "'";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
} catch (UserAdminException e) {
String msg = "Error occurred while updating permissions of the role '" + roleName + "'";
log.error(msg, e);
@ -559,9 +567,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
if (!userStoreManager.isExistingRole(roleName)) {
return Response.status(404).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
roleName + "'").build()).build();
String msg = "No role exists with the name : " + roleName ;
return Response.status(404).entity(msg).build();
}
final AuthorizationManager authorizationManager = userRealm.getAuthorizationManager();

@ -157,10 +157,8 @@ public class UserManagementServiceImpl implements UserManagementService {
" already exists. Therefore, request made to add user was refused.");
}
// returning response with bad request state
return Response.status(Response.Status.CONFLICT).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
userInfo.getUsername() + " already exists. Therefore, request made to add user " +
"was refused.").build()).build();
String msg = "User by username: " + userInfo.getUsername() + " already exists. Try with another username." ;
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
String initialUserPassword;
@ -290,9 +288,8 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"User doesn't exist.").build()).build();
String msg = "User by username: " + username + " does not exist.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
BasicUserInfo user = this.getBasicUserInfo(username);
@ -318,9 +315,8 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + username +
" doesn't exists. Therefore, request made to update user was refused.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
username + " doesn't exist.").build()).build();
String msg = "User by username: " + username + " does not exist.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
Map<String, String> defaultUserClaims =
@ -396,9 +392,8 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for removal.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User '" +
username + "' does not exist for removal.").build()).build();
String msg = "User by username: " + username + " does not exist for removal.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
// Un-enroll all devices for the user
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
@ -430,9 +425,8 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for role retrieval.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + username +
" does not exist for role retrieval.").build()).build();
String msg = "User by username: " + username + " does not exist for role retrieval.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
RoleList result = new RoleList();
@ -867,8 +861,8 @@ public class UserManagementServiceImpl implements UserManagementService {
try {
ifSinceDate = format.parse(ifModifiedSince);
} catch (ParseException e) {
return Response.status(400).entity(new ErrorResponse.ErrorResponseBuilder()
.setMessage("Invalid date string is provided in 'If-Modified-Since' header").build()).build();
String msg = "Invalid date string is provided in [If-Modified-Since] header";
return Response.status(400).entity(msg).build();
}
ifModifiedSinceTimestamp = ifSinceDate.getTime();
isIfModifiedSinceSet = true;
@ -879,8 +873,8 @@ public class UserManagementServiceImpl implements UserManagementService {
try {
sinceDate = format.parse(since);
} catch (ParseException e) {
return Response.status(400).entity(new ErrorResponse.ErrorResponseBuilder()
.setMessage("Invalid date string is provided in 'since' filter").build()).build();
String msg = "Invalid date string is provided in [since] filter";
return Response.status(400).entity(msg).build();
}
sinceTimestamp = sinceDate.getTime();
timestamp = sinceTimestamp / 1000;
@ -1094,8 +1088,7 @@ public class UserManagementServiceImpl implements UserManagementService {
if (!userStoreManager.isExistingUser(username)) {
String message = "User by username: " + username + " does not exist for permission retrieval.";
log.error(message);
return Response.status(Response.Status.NOT_FOUND)
.entity(new ErrorResponse.ErrorResponseBuilder().setMessage(message).build()).build();
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
// Get a list of roles which the user assigned to
List<String> roles = getFilteredRoles(userStoreManager, username);

@ -81,9 +81,8 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
applicationWrapper.getDeviceIdentifiers().size() > 0) {
activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"No application installation criteria i.e. user/role/device is given").build()).build();
String msg = "No application installation criteria i.e. user/role/device is given";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
return Response.status(Response.Status.ACCEPTED).entity(activity).build();
@ -131,9 +130,8 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
applicationWrapper.getDeviceIdentifiers().size() > 0) {
activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"No application un-installation criteria i.e. user/role/device is given").build()).build();
String msg = "No application un-installation criteria i.e. user/role/device is given";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
return Response.status(Response.Status.ACCEPTED).entity(activity).build();

@ -169,7 +169,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UserNotFoundException e) {
String msg = "Couldn't found the owner in user store to update the owner of devices.";
String msg = "Could not found the owner in user store to update the owner of devices.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
@ -197,8 +197,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
} catch (InvalidDeviceException e) {
String msg = "Found Invalid devices";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -222,7 +221,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Bad request, can't proceed. Hence verify the request and re-try";
String msg = "Bad request, cannot proceed. Hence verify the request and re-try";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (DeviceManagementException e) {
@ -230,7 +229,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceNotFoundException e) {
String msg = "Couldn't find an device for device identifier: " + deviceIdentifier;
String msg = "Could not find an device";
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}

@ -156,7 +156,7 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupAlreadyExistException e) {
String msg = "Group already exists with name " + group.getName() + ".";
String msg = "Group already exists with name : " + group.getName() + ". Try with another group name.";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}

@ -49,6 +49,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.ProfileFeature;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.Scope;
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.policy.mgt.common.PolicyPayloadValidator;
@ -849,8 +850,7 @@ public class RequestValidationUtil {
if (geofenceWrapper.getFenceName() == null || geofenceWrapper.getFenceName().trim().isEmpty()) {
String msg = "Geofence name should not be null or empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
if (geofenceWrapper.getGeoJson() != null && !geofenceWrapper.getGeoJson().trim().isEmpty()) {
isGeoJsonExists = true;
@ -858,26 +858,22 @@ public class RequestValidationUtil {
if ((geofenceWrapper.getLatitude() < -90 || geofenceWrapper.getLatitude() > 90) && !isGeoJsonExists) {
String msg = "Latitude should be a value between -90 and 90";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
if ((geofenceWrapper.getLongitude() < -180 || geofenceWrapper.getLongitude() > 180) && !isGeoJsonExists) {
String msg = "Longitude should be a value between -180 and 180";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
if (geofenceWrapper.getRadius() < 1 && !isGeoJsonExists) {
String msg = "Minimum radius of the fence should be 1m";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
if (geofenceWrapper.getFenceShape().trim().isEmpty()) {
String msg = "Fence shape should not be empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
}
@ -889,23 +885,20 @@ public class RequestValidationUtil {
if (eventConfig == null ||eventConfig.isEmpty()) {
String msg = "Event configuration is mandatory, since should not be null or empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
for (EventConfig config : eventConfig) {
if (config.getActions() == null || config.getActions().isEmpty()) {
String msg = "Event actions are mandatory, since should not be null or empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
if (config.getEventLogic() == null || config.getEventLogic().trim().isEmpty()) {
String msg = "Event logic is mandatory, since should not be null or empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
throw new BadRequestException(msg);
}
}
}

Loading…
Cancel
Save