use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method getAPIsByGatewayLabel.
@Override
public List<API> getAPIsByGatewayLabel(List<String> gatewayLabels) throws APIManagementException {
List<API> apiList;
try {
if (gatewayLabels != null) {
apiList = apiDAO.getAPIsByGatewayLabel(gatewayLabels);
} else {
String msg = "Gateway labels cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
}
} catch (APIMgtDAOException e) {
String msg = "Error occurred while getting the API list in given gateway labels";
log.error(msg, e);
throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
return apiList;
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method addApiPolicy.
@Override
public String addApiPolicy(APIPolicy policy) throws APIManagementException {
try {
String policyUuid = policy.getUuid();
if (policyUuid == null) {
if (log.isDebugEnabled()) {
log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
}
policyUuid = UUID.randomUUID().toString();
policy.setUuid(policyUuid);
}
policyDAO.addApiPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
apiGateway.addPolicy(policyValidationData);
return policyUuid;
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't add API policy for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method getAPIsByStatus.
@Override
public List<API> getAPIsByStatus(List<String> gatewayLabels, String status) throws APIManagementException {
List<API> apiList;
try {
if (gatewayLabels != null && status != null) {
apiList = apiDAO.getAPIsByStatus(gatewayLabels, status);
} else {
if (gatewayLabels == null) {
String msg = "Gateway labels cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
} else {
String msg = "Status cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.STATUS_CANNOT_BE_NULL);
}
}
} catch (APIMgtDAOException e) {
String msg = "Error occurred while getting the API list in given states";
log.error(msg, e);
throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
return apiList;
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method updateBlockConditionStateByUUID.
@Override
public boolean updateBlockConditionStateByUUID(String uuid, Boolean state) throws APIManagementException {
try {
if (policyDAO.updateBlockConditionStateByUUID(uuid, state)) {
BlockConditions blockConditions = getBlockConditionByUUID(uuid);
apiGateway.updateBlockCondition(blockConditions);
return true;
} else {
return false;
}
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't update block condition with UUID: " + uuid + ", state: " + state;
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method addApplicationPolicy.
@Override
public String addApplicationPolicy(ApplicationPolicy policy) throws APIManagementException {
try {
String policyUuid = policy.getUuid();
if (policyUuid == null) {
if (log.isDebugEnabled()) {
log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
}
policyUuid = UUID.randomUUID().toString();
policy.setUuid(policyUuid);
}
policyDAO.addApplicationPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
apiGateway.addPolicy(policyValidationData);
return policyUuid;
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't add Application for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
Aggregations