Merge branch 'application-mgt-new' into 'application-mgt-new'

Improve app retrieving method in publisher

See merge request entgra/carbon-device-mgt!141
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
commit b2650f5c9b

@ -32,12 +32,6 @@ public class Review {
@ApiModelProperty(name = "content", value = "Review message.") @ApiModelProperty(name = "content", value = "Review message.")
private String content; private String content;
@ApiModelProperty(name = "rootParentId", value = "Root Parent id of the review")
private int rootParentId;
@ApiModelProperty(name = "immediateParentId", value = "Immediate Parent id of the review")
private int immediateParentId;
@ApiModelProperty(name = "username", value = "Username odf the Review creator") @ApiModelProperty(name = "username", value = "Username odf the Review creator")
private String username; private String username;
@ -50,6 +44,12 @@ public class Review {
@ApiModelProperty(name = "rating", value = "Rating value of the application release") @ApiModelProperty(name = "rating", value = "Rating value of the application release")
private int rating; private int rating;
@ApiModelProperty(name = "releaseUuid", value = "UUID of the review associated application")
private String releaseUuid;
@ApiModelProperty(name = "releaseVersion", value = "Version of the review associated application")
private String releaseVersion;
@ApiModelProperty(name = "replies", value = "Replying reviews") @ApiModelProperty(name = "replies", value = "Replying reviews")
private List<Review> replies; private List<Review> replies;
@ -69,22 +69,6 @@ public class Review {
this.content = content; this.content = content;
} }
public int getRootParentId() {
return rootParentId;
}
public void setRootParentId(int rootParentId) {
this.rootParentId = rootParentId;
}
public int getImmediateParentId() {
return immediateParentId;
}
public void setImmediateParentId(int immediateParentId) {
this.immediateParentId = immediateParentId;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -120,4 +104,12 @@ public class Review {
public List<Review> getReplies() { return replies; } public List<Review> getReplies() { return replies; }
public void setReplies(List<Review> replies) { this.replies = replies; } public void setReplies(List<Review> replies) { this.replies = replies; }
public String getReleaseUuid() { return releaseUuid; }
public void setReleaseUuid(String releaseUuid) { this.releaseUuid = releaseUuid; }
public String getReleaseVersion() { return releaseVersion; }
public void setReleaseVersion(String releaseVersion) { this.releaseVersion = releaseVersion; }
} }

@ -122,7 +122,7 @@ public interface ApplicationManager {
* @return the Application Release identified by the UUID * @return the Application Release identified by the UUID
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException; Application getApplicationByUuid(String uuid) throws ApplicationManagementException;
/** /**
* To get the ApplicationDTO for given application relase UUID. * To get the ApplicationDTO for given application relase UUID.

@ -90,7 +90,7 @@ import java.util.List;
* @return {@link List}List of all reviews for the application release * @return {@link List}List of all reviews for the application release
* @throws ReviewManagementDAOException Review management DAO exception * @throws ReviewManagementDAOException Review management DAO exception
**/ **/
List<ReviewDTO> getAllActiveReleaseReviews(int releaseId, PaginationRequest request, int tenantId) List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException; throws ReviewManagementDAOException;
List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId) List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId)

@ -110,7 +110,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT rv.ID FROM AP_APP_REVIEW rv " + "WHERE rv.AP_APP_RELEASE_ID IN (", "SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (",
") AND rv.USERNAME = ? AND rv.TENANT_ID = ?"); ") AND rv.USERNAME = ? AND rv.TENANT_ID = ?");
appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add); appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
@ -118,7 +118,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
for (Integer deviceId : appReleaseIds) { for (Integer deviceId : appReleaseIds) {
ps.setObject(index++, deviceId); ps.setObject(index++, deviceId);
} }
ps.setInt(index++, tenantId); ps.setString(index++, username);
ps.setInt(index, tenantId); ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
return rs.next(); return rs.next();
@ -258,7 +258,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
@Override @Override
public List<ReviewDTO> getAllActiveReleaseReviews(int releaseId, PaginationRequest request, int tenantId) public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -283,7 +283,6 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID "
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND " + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
+ "AP_APP_REVIEW.TENANT_ID = ? " + "AP_APP_REVIEW.TENANT_ID = ? "
+ "LIMIT ? OFFSET ?"; + "LIMIT ? OFFSET ?";
try (PreparedStatement statement = conn.prepareStatement(sql)) { try (PreparedStatement statement = conn.prepareStatement(sql)) {

@ -896,49 +896,50 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException{ public Application getApplicationByUuid(String uuid) throws ApplicationManagementException{
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isVisibleAppRelease = false; boolean isVisibleApp = false;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.getReleaseByUUID(uuid, tenantId); ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(uuid, tenantId);
if (applicationReleaseDTO == null) {
String msg = "Couldn't find an application release for the UUID: " + uuid; if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + uuid;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) {
return null;
}
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRolesByUUID(uuid, tenantId); List<String> tags = this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId);
List<String> categories = this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId);
applicationDTO.setTags(tags);
applicationDTO.setAppCategories(categories);
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId);
if (!unrestrictedRoles.isEmpty()) { if (!unrestrictedRoles.isEmpty()) {
if (hasUserRole(unrestrictedRoles, userName)) { if (hasUserRole(unrestrictedRoles, userName)) {
isVisibleAppRelease = true; isVisibleApp = true;
} }
} else { } else {
isVisibleAppRelease = true; isVisibleApp = true;
} }
if (!isVisibleAppRelease) { if (!isVisibleApp) {
String msg = "You are trying to access release of visibility restricted application. You don't have " String msg = "You are trying to access visibility restricted application. You don't have required "
+ "required roles to view this application,"; + "roles to view this application,";
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
return APIUtil.releaseDtoToRelease(applicationReleaseDTO); return APIUtil.appDtoToAppResponse(applicationDTO);
} catch (LifecycleManagementException e) {
String msg = "Error occurred when getting the end state of the application lifecycle flow";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "User-store exception while getting application with the application release UUID: " + uuid; String msg = "User-store exception occurred while getting application for application release UUID " + uuid;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
//todo String msg = "Error occurred while getting dta which are related to Application.";
throw new ApplicationManagementException(""); log.error(msg);
throw new ApplicationManagementException(msg);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }

@ -238,8 +238,8 @@ public class ReviewManagerImpl implements ReviewManager {
Review review = new Review(); Review review = new Review();
review.setId(reviewDTO.getId()); review.setId(reviewDTO.getId());
review.setContent(reviewDTO.getContent()); review.setContent(reviewDTO.getContent());
review.setRootParentId(reviewDTO.getRootParentId()); review.setReleaseUuid(reviewDTO.getReleaseUuid());
review.setImmediateParentId(reviewDTO.getImmediateParentId()); review.setReleaseVersion(reviewDTO.getReleaseVersion());
review.setCreatedAt(reviewDTO.getCreatedAt()); review.setCreatedAt(reviewDTO.getCreatedAt());
review.setModifiedAt(reviewDTO.getModifiedAt()); review.setModifiedAt(reviewDTO.getModifiedAt());
review.setRating(reviewDTO.getRating()); review.setRating(reviewDTO.getRating());
@ -353,7 +353,7 @@ public class ReviewManagerImpl implements ReviewManager {
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
return getReviewTree(this.reviewDAO.getAllActiveReleaseReviews(releaseDTO.getId(), request, tenantId)); return getReviewTree(this.reviewDAO.getAllReleaseReviews(releaseDTO.getId(), request, tenantId));
} catch (ReviewManagementDAOException e) { } catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while getting all reviews for application uuid: " + uuid, throw new ReviewManagementException("Error occured while getting all reviews for application uuid: " + uuid,
e); e);

@ -217,7 +217,7 @@ public interface ApplicationManagementPublisherAPI {
message = "Internal Server Error. \n Error occurred while getting relevant application release.", message = "Internal Server Error. \n Error occurred while getting relevant application release.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getApplicationRelease( Response getApplicationByUUID(
@ApiParam( @ApiParam(
name = "uuid", name = "uuid",
value = "application release uuid", value = "application release uuid",

@ -135,18 +135,17 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@GET @GET
@Consumes("application/json") @Consumes("application/json")
@Path("/release/{uuid}") @Path("/release/{uuid}")
public Response getApplicationRelease( public Response getApplicationByUUID(
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
//todo return application Application application = applicationManager.getApplicationByUuid(uuid);
ApplicationRelease applicationRelease = applicationManager.getApplicationReleaseByUUID(uuid); if (application == null){
if (applicationRelease == null){
String msg = "Application release is in the end state of the application lifecycle flow."; String msg = "Application release is in the end state of the application lifecycle flow.";
log.error(msg); log.error(msg);
return Response.status(Response.Status.OK).entity(msg).build(); return Response.status(Response.Status.OK).entity(msg).build();
} }
return Response.status(Response.Status.OK).entity(applicationRelease).build(); return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Application Release with UUID: " + uuid + " is not found"; String msg = "Application Release with UUID: " + uuid + " is not found";
log.error(msg, e); log.error(msg, e);

Loading…
Cancel
Save