use of org.wso2.micro.gateway.core.validation.Validate in project siddhi by wso2.
the class ValidateTestCase method validateTest1.
@Test
public void validateTest1() throws InterruptedException {
log.info("validate test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('validateTest') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[symbol is null] " + "select symbol, price " + "insert into outputStream;";
siddhiManager.validateSiddhiApp(siddhiApp);
}
use of org.wso2.micro.gateway.core.validation.Validate in project carbon-apimgt by wso2.
the class PolicyDAOImpl method isValidApplication.
/**
* validate the blocking application.
*
* @param appName name of the application
* @param uuid uuid of the application
* @return return true/false depends of the success
* @throws APIMgtDAOException if failed validating application
*/
private boolean isValidApplication(String appName, String uuid) throws APIMgtDAOException {
String query = "SELECT 1 FROM AM_APPLICATION WHERE UUID = ? AND NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
connection.setAutoCommit(false);
statement.setString(1, uuid);
statement.setString(2, appName);
try (ResultSet resultSet = statement.executeQuery()) {
return resultSet.next();
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "checking if Block condition with Application Name " + appName + " , Application ID = " + uuid + " exists", e);
}
}
use of org.wso2.micro.gateway.core.validation.Validate in project carbon-apimgt by wso2.
the class APIPublisherImpl method searchAPIs.
/**
* @param limit Limit
* @param offset Offset
* @param query Search query
* @return List of APIS.
* @throws APIManagementException If failed to formatApiSearch APIs.
*/
@Override
public List<API> searchAPIs(Integer limit, Integer offset, String query) throws APIManagementException {
List<API> apiResults;
String user = getUsername();
Set<String> roles = new HashSet<>();
try {
// TODO: Need to validate users roles against results returned
if (!"admin".equals(user)) {
// Whenever call identity provider should convert pseudo name to actual name
String userId = getIdentityProvider().getIdOfUser(user);
roles = new HashSet<>(getIdentityProvider().getRoleIdsOfUser(userId));
}
if (query != null && !query.isEmpty()) {
String[] attributes = query.split(ATTRIBUTE_DELIMITER);
Map<String, String> attributeMap = new HashMap<>();
boolean isFullTextSearch = false;
String searchAttribute, searchValue;
if (!query.contains(KEY_VALUE_DELIMITER)) {
isFullTextSearch = true;
} else {
log.debug("Search query: " + query);
for (String attribute : attributes) {
searchAttribute = attribute.split(KEY_VALUE_DELIMITER)[0];
searchValue = attribute.split(KEY_VALUE_DELIMITER)[1];
log.debug(searchAttribute + KEY_VALUE_DELIMITER + searchValue);
attributeMap.put(searchAttribute, searchValue);
}
}
if (isFullTextSearch) {
apiResults = getApiDAO().searchAPIs(roles, user, query, offset, limit);
} else {
log.debug("Attributes:", attributeMap.toString());
apiResults = getApiDAO().attributeSearchAPIs(roles, user, attributeMap, offset, limit);
}
} else {
apiResults = getApiDAO().getAPIs(roles, user);
}
return apiResults;
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while Searching the API with query " + query;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (IdentityProviderException e) {
String errorMsg = "Error occurred while calling SCIM endpoint to retrieve user " + user + "'s information";
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.micro.gateway.core.validation.Validate in project carbon-apimgt by wso2.
the class APIPublisherImpl method createNewAPIVersion.
/**
* Create a new version of the <code>api</code>, with version <code>newVersion</code>
*
* @param apiId The API to be copied
* @param newVersion The version of the new API
* @return UUID of the newly created version.
* @throws APIManagementException If an error occurs while trying to create
* the new version of the API
*/
@Override
public String createNewAPIVersion(String apiId, String newVersion) throws APIManagementException {
String newVersionedId;
LifecycleState lifecycleState;
// validate parameters
if (StringUtils.isEmpty(newVersion)) {
String errorMsg = "New API version cannot be empty";
log.error(errorMsg);
throw new APIManagementException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
if (StringUtils.isEmpty(apiId)) {
String errorMsg = "API ID cannot be empty";
log.error(errorMsg);
throw new APIManagementException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
try {
API api = getApiDAO().getAPI(apiId);
if (api.getVersion().equals(newVersion)) {
String errMsg = "New API version " + newVersion + " cannot be same as the previous version for " + "API " + api.getName();
log.error(errMsg);
throw new APIManagementException(errMsg, ExceptionCodes.API_ALREADY_EXISTS);
}
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.id(UUID.randomUUID().toString());
apiBuilder.version(newVersion);
apiBuilder.context(api.getContext().replace(api.getVersion(), newVersion));
lifecycleState = getApiLifecycleManager().addLifecycle(APIMgtConstants.API_LIFECYCLE, getUsername());
apiBuilder.associateLifecycle(lifecycleState);
apiBuilder.copiedFromApiId(api.getId());
if (StringUtils.isEmpty(apiBuilder.getApiDefinition())) {
apiBuilder.apiDefinition(apiDefinitionFromSwagger20.generateSwaggerFromResources(apiBuilder));
}
getApiDAO().addAPI(apiBuilder.build());
newVersionedId = apiBuilder.getId();
sendNotification(apiId, apiBuilder.getName(), newVersion);
} catch (APIMgtDAOException e) {
String errorMsg = "Couldn't create new API version from " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (LifecycleException e) {
String errorMsg = "Couldn't Associate new API Lifecycle from " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_LIFECYCLE_EXCEPTION);
}
return newVersionedId;
}
use of org.wso2.micro.gateway.core.validation.Validate in project carbon-apimgt by wso2.
the class APIStoreImpl method createNewCompositeApiVersion.
/**
* {@inheritDoc}
*/
@Override
public String createNewCompositeApiVersion(String apiId, String newVersion) throws APIManagementException {
// validate parameters
if (StringUtils.isEmpty(newVersion)) {
String errorMsg = "New API version cannot be empty";
log.error(errorMsg);
throw new APIManagementException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
if (StringUtils.isEmpty(apiId)) {
String errorMsg = "API ID cannot be empty";
log.error(errorMsg);
throw new APIManagementException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
String newVersionedId;
try {
CompositeAPI api = getApiDAO().getCompositeAPI(apiId);
if (api.getVersion().equals(newVersion)) {
String errMsg = "New API version " + newVersion + " cannot be same as the previous version for " + "API " + api.getName();
log.error(errMsg);
throw new APIManagementException(errMsg, ExceptionCodes.API_ALREADY_EXISTS);
}
CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder(api);
apiBuilder.id(UUID.randomUUID().toString());
apiBuilder.version(newVersion);
apiBuilder.context(api.getContext().replace(api.getVersion(), newVersion));
apiBuilder.copiedFromApiId(api.getId());
if (StringUtils.isEmpty(apiBuilder.getApiDefinition())) {
apiBuilder.apiDefinition(apiDefinitionFromSwagger20.generateSwaggerFromResources(apiBuilder));
}
getApiDAO().addApplicationAssociatedAPI(apiBuilder.build());
newVersionedId = apiBuilder.getId();
} catch (APIMgtDAOException e) {
String errorMsg = "Couldn't create new API version from " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
return newVersionedId;
}
Aggregations