src/main/java/org/edgegallery/appstore/interfaces/order/facade/OrderServiceFacade.java
public ResponseEntity<ResponseObject> deactivateOrder(String userId, String userName, String orderId,
        String token) {
        Order order = orderRepository.findByOrderId(orderId)
            .orElseThrow(() -> new EntityNotFoundException(Order.class, orderId, ResponseConst.RET_ORDER_NOT_FOUND));
        if (order.getStatus() != EnumOrderStatus.ACTIVATED && order.getStatus() != EnumOrderStatus.DEACTIVATE_FAILED) {
            throw new AppException("inactivated orders can't be deactivated.",
                ResponseConst.RET_NOT_ALLOWED_DEACTIVATE_ORDER);
        }
        if (!userId.equals(order.getUserId()) && !Consts.SUPER_ADMIN_NAME.equals(userName)) {
            throw new PermissionNotAllowedException("can not deactivate order",
                ResponseConst.RET_NO_ACCESS_DEACTIVATE_ORDER, userName);
        }

        // undeploy app, if success, update status to deactivated, if failed, update status to deactivate_failed
        String unDeployAppResult = orderService.unDeployApp(order, userId, token);
        if (StringUtils.isEmpty(unDeployAppResult)) {
            LOGGER.error("Failed to utilize delete server interface, undeploy app result is null.");
            throw new AppException("Failed to utilize delete server interface.",
                ResponseConst.RET_DELETE_SERVER_FAILED);
        }

        String resultMessage = "deactivate order success";
        if (unDeployAppResult.equalsIgnoreCase(FAIL_TO_DELETE_PACKAGE)
            || unDeployAppResult.equalsIgnoreCase(FAIL_TO_DELETE_INSTANTIATION)) {
            LOGGER.error("Failed to undeploy package.");
            order.setStatus(EnumOrderStatus.DEACTIVATE_FAILED);
            resultMessage = "fail to deactivate order";
        } else if (unDeployAppResult.equalsIgnoreCase(DELETE_SERVER_SUCCESS)) {
            LOGGER.info("Undeploy package successfully.");
            order.setStatus(EnumOrderStatus.DEACTIVATED);
        }
        orderRepository.updateOrder(order);
        return ResponseEntity.ok(new ResponseObject(resultMessage,
            new ErrorMessage(ResponseConst.RET_SUCCESS, null), resultMessage));
    }
/**
     * deactivate order.
     *
     * @param userId user id
     * @param userName name of current user
     * @param orderId order id
     * @return result
     */
deactivate order.
@param userId user id
@param userName name of current user
@param orderId order id
@return result
deactivate order . @param userId user id @param userName name of current user @param orderId order id @return result
public ResponseEntity<ResponseObject> deactivateOrder(String userId, String userName, String orderId,
        String token) {
        Order order = orderRepository.findByOrderId(orderId)
            .orElseThrow(() -> new EntityNotFoundException(Order.class, orderId, ResponseConst.RET_ORDER_NOT_FOUND));
        if (order.getStatus() != EnumOrderStatus.ACTIVATED && order.getStatus() != EnumOrderStatus.DEACTIVATE_FAILED) {
            throw new AppException("inactivated orders can't be deactivated.",
                ResponseConst.RET_NOT_ALLOWED_DEACTIVATE_ORDER);
        }
        if (!userId.equals(order.getUserId()) && !Consts.SUPER_ADMIN_NAME.equals(userName)) {
            throw new PermissionNotAllowedException("can not deactivate order",
                ResponseConst.RET_NO_ACCESS_DEACTIVATE_ORDER, userName);
        }
        String unDeployAppResult = orderService.unDeployApp(order, userId, token);
        if (StringUtils.isEmpty(unDeployAppResult)) {
            LOGGER.error("Failed to utilize delete server interface, undeploy app result is null.");
            throw new AppException("Failed to utilize delete server interface.",
                ResponseConst.RET_DELETE_SERVER_FAILED);
        }
        String resultMessage = "deactivate order success";
        if (unDeployAppResult.equalsIgnoreCase(FAIL_TO_DELETE_PACKAGE)
            || unDeployAppResult.equalsIgnoreCase(FAIL_TO_DELETE_INSTANTIATION)) {
            LOGGER.error("Failed to undeploy package.");
            order.setStatus(EnumOrderStatus.DEACTIVATE_FAILED);
            resultMessage = "fail to deactivate order";
        } else if (unDeployAppResult.equalsIgnoreCase(DELETE_SERVER_SUCCESS)) {
            LOGGER.info("Undeploy package successfully.");
            order.setStatus(EnumOrderStatus.DEACTIVATED);
        }
        orderRepository.updateOrder(order);
        return ResponseEntity.ok(new ResponseObject(resultMessage,
            new ErrorMessage(ResponseConst.RET_SUCCESS, null), resultMessage));
    }
public ResponseEntity < ResponseObject > deactivateOrder ( String userId , String userName , String orderId , String token ) { Order order = orderRepository . findByOrderId ( orderId ) . orElseThrow ( ( ) -> new EntityNotFoundException ( Order . class , orderId , ResponseConst . RET_ORDER_NOT_FOUND ) ) ; if ( order . getStatus ( ) != EnumOrderStatus . ACTIVATED && order . getStatus ( ) != EnumOrderStatus . DEACTIVATE_FAILED ) { throw new AppException ( "inactivated orders can't be deactivated." , ResponseConst . RET_NOT_ALLOWED_DEACTIVATE_ORDER ) ; } if ( ! userId . equals ( order . getUserId ( ) ) && ! Consts . SUPER_ADMIN_NAME . equals ( userName ) ) { throw new PermissionNotAllowedException ( "can not deactivate order" , ResponseConst . RET_NO_ACCESS_DEACTIVATE_ORDER , userName ) ; } String unDeployAppResult = orderService . unDeployApp ( order , userId , token ) ; if ( StringUtils . isEmpty ( unDeployAppResult ) ) { LOGGER . error ( "Failed to utilize delete server interface, undeploy app result is null." ) ; throw new AppException ( "Failed to utilize delete server interface." , ResponseConst . RET_DELETE_SERVER_FAILED ) ; } String resultMessage = "deactivate order success" ; if ( unDeployAppResult . equalsIgnoreCase ( FAIL_TO_DELETE_PACKAGE ) || unDeployAppResult . equalsIgnoreCase ( FAIL_TO_DELETE_INSTANTIATION ) ) { LOGGER . error ( "Failed to undeploy package." ) ; order . setStatus ( EnumOrderStatus . DEACTIVATE_FAILED ) ; resultMessage = "fail to deactivate order" ; } else if ( unDeployAppResult . equalsIgnoreCase ( DELETE_SERVER_SUCCESS ) ) { LOGGER . info ( "Undeploy package successfully." ) ; order . setStatus ( EnumOrderStatus . DEACTIVATED ) ; } orderRepository . updateOrder ( order ) ; return ResponseEntity . ok ( new ResponseObject ( resultMessage , new ErrorMessage ( ResponseConst . RET_SUCCESS , null ) , resultMessage ) ) ; }
deactivate order.
deactivate order .
// undeploy app, if success, update status to deactivated, if failed, update status to deactivate_failed