Add App updating API

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 460394c9da
commit 7703d217f9

@ -168,7 +168,7 @@ public interface ApplicationDAO {
* @return Updated ApplicationDTO. * @return Updated ApplicationDTO.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/ */
ApplicationDTO editApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException; boolean updateApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException;
/** /**
* To delete the application * To delete the application

@ -583,66 +583,36 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public ApplicationDTO editApplication(ApplicationDTO application, int tenantId) public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null;
//todo this is wrong
ApplicationDTO existingApplication = this.getApplicationById(application.getId(), tenantId);
if (existingApplication == null) {
throw new ApplicationManagementDAOException("There doesn't have an application for updating");
}
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "UPDATE AP_APP SET "; String sql = "UPDATE AP_APP AP " +
"SET " +
if (application.getName() != null && !application.getName().equals(existingApplication.getName())) { "AP.NAME = ?, " +
sql += "NAME = ?, "; "AP.DESCRIPTION = ?, " +
} "AP.SUB_TYPE = ?, " +
if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { "AP.CURRENCY = ? " +
sql += "TYPE = ?, "; "WHERE AP.ID = ? AND AP.TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, applicationDTO.getName());
stmt.setString(2, applicationDTO.getDescription());
stmt.setString(3, applicationDTO.getSubType());
stmt.setString(4, applicationDTO.getPaymentCurrency());
stmt.setInt(5, applicationDTO.getId());
stmt.setInt(6, tenantId);
return stmt.executeUpdate() > 0;
} }
if (application.getAppCategory() != null && !application.getAppCategory().equals(
existingApplication.getAppCategory())) {
sql += "APP_CATEGORY = ?, ";
}
// if (application.getIsRestricted() != existingApplication.getIsRestricted()) {
// sql += "RESTRICTED = ? ";
// }
if (!application.getSubType().equals(existingApplication.getSubType())) {
sql += "SUB_TYPE = ? ";
}
sql += "WHERE ID = ?";
stmt = conn.prepareStatement(sql);
if (application.getName() != null && !application.getName().equals(existingApplication.getName())) {
stmt.setString(paramIndex++, application.getName());
}
if (application.getType() != null && !application.getType().equals(existingApplication.getType())) {
stmt.setString(paramIndex++, application.getType());
}
if (application.getAppCategory() != null && !application.getAppCategory().equals(
existingApplication.getAppCategory())) {
stmt.setString(paramIndex++, application.getAppCategory());
}
// if (application.getIsRestricted() != existingApplication.getIsRestricted()) {
// stmt.setBoolean(paramIndex++, application.getIsRestricted());
// }
if (!application.getSubType().equals(existingApplication.getSubType())) {
stmt.setString(paramIndex++, application.getSubType());
}
stmt.setInt(paramIndex, application.getId());
stmt.executeUpdate();
return application;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Error occurred while obtaining the DB connection to update the application.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the application", e); String msg = "Error occurred when obtaining database connection for updating the application.";
} finally { log.error(msg);
Util.cleanupResources(stmt, null); throw new ApplicationManagementDAOException(msg, e);
} }
} }

@ -1589,8 +1589,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDAO.deleteTags(removingTagList, applicationId, tenantId); applicationDAO.deleteTags(removingTagList, applicationId, tenantId);
} }
} }
//todo if (!applicationDAO.updateApplication(applicationDTO, tenantId)){
applicationDAO.editApplication(applicationDTO, tenantId); String msg = "Any application is not updated for the application ID: " + applicationId;
log.error(msg);
throw new ApplicationManagementException(msg);
}
} catch (UserStoreException e) { } catch (UserStoreException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( throw new ApplicationManagementException(

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO; import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
@ -34,7 +33,6 @@ import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseW
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
@ -316,10 +314,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
/*
//todo ----------------------
*/
@PUT @PUT
@Consumes("application/json") @Consumes("application/json")
@Path("/{appId}") @Path("/{appId}")
@ -328,23 +322,29 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Valid ApplicationWrapper applicationWrapper) { @Valid ApplicationWrapper applicationWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
//todo wrong
applicationManager.updateApplication(applicationId, applicationWrapper); applicationManager.updateApplication(applicationId, applicationWrapper);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Application was updated successfully. ApplicationID " + applicationId).build(); .entity("Application was updated successfully for ApplicationID: " + applicationId).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error(e.getMessage()); log.error(e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build(); return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
} catch (ForbiddenException e) { } catch (BadRequestException e) {
log.error(e.getMessage()); String msg = "Error occurred while modifying the application. Found bad request payload for updating the "
return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).build(); + "application";
} catch (ApplicationManagementException e) {
String msg = "Error occurred while modifying the application";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
catch (ApplicationManagementException e) {
String msg = "Internal Error occurred while modifying the application.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} }
/*
//todo ----------------------
*/
@Override @Override
@PUT @PUT
@Path("/{deviceType}/{appId}/{uuid}") @Path("/{deviceType}/{appId}/{uuid}")

Loading…
Cancel
Save