use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddExistingScopeToApi.
@Test(description = "Add existing Scope to API")
public void testAddExistingScopeToApi() throws APIManagementException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
KeyManager keyManager = Mockito.mock(KeyManager.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
String oldSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
Scope scope = new Scope("api_create", "api_create");
Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(oldSwagger);
try {
apiPublisher.addScopeToTheApi(api.getId(), scope);
Assert.fail();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Scope already registered");
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.
the class OAuth2Authenticator method validateTokenAndScopes.
private boolean validateTokenAndScopes(Request request, ServiceMethodInfo serviceMethodInfo, String accessToken) throws APIMgtSecurityException {
// Map<String, String> tokenInfo = validateToken(accessToken);
AccessTokenInfo accessTokenInfo = validateToken(accessToken);
String restAPIResource = getRestAPIResource(request);
// scope validation
return validateScopes(request, serviceMethodInfo, accessTokenInfo.getScopes(), restAPIResource);
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method fillScopeInfo.
private void fillScopeInfo(ScopeInfoType scopeInfo, ScopeDAO scope) {
scopeInfo.setSiid(scope.getScopeInstanceId().toString());
scopeInfo.setName(scope.getName());
scopeInfo.setStatus(odeScopeStatusToManagementAPIStatus(scope.getState()));
Children_type0 childScopes = new Children_type0();
if (scope.isChildrenExist()) {
}
for (ScopeDAO childScope : scope.getChildScopes()) {
ScopeInfoType childScopeInfo = new ScopeInfoType();
fillScopeInfo(childScopeInfo, childScope);
childScopes.addChildRef(childScopeInfo);
}
scopeInfo.setChildren(childScopes);
scopeInfo.setVariables(getVariables(scope));
if (!scope.getCorrelationDTOs().isEmpty()) {
scopeInfo.setCorrelationSets(getCorrelationPropertires(scope));
}
scopeInfo.setActivities(getActivities(scope));
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getScopeInfo.
private ScopeInfoType getScopeInfo(ScopeDAO scope) throws InstanceManagementException {
final ScopeInfoType scopeInfo = new ScopeInfoType();
/*ScopeDAO scope = conn.getScopeEagerly(siid);*/
if (scope == null) {
// String errMsg = "Scope " + siid +" not found.";
String errMsg = "Scope " + " not found.";
log.error(errMsg);
throw new InstanceManagementException(errMsg);
}
fillScopeInfo(scopeInfo, scope);
return scopeInfo;
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getActivitiesWithEvents.
private ActivitiesWithEvents_type0 getActivitiesWithEvents(ScopeDAO scope) {
ActivitiesWithEvents_type0 activitiesWithEvents = new ActivitiesWithEvents_type0();
Collection<ActivityRecoveryDAO> recoveries = scope.getProcessInstance().getActivityRecoveries();
// List<BpelEvent> events = scope.listEvents();
Set<EventDAOImpl> eventsEntities = ((ScopeDAOImpl) scope).getEvents();
List<BpelEvent> events = new ArrayList<BpelEvent>();
for (EventDAOImpl event : eventsEntities) {
events.add(event.getEvent());
}
ActivityStateAndEventDocumentBuilder docBuilder = new ActivityStateAndEventDocumentBuilder();
for (BpelEvent e : events) {
docBuilder.onEvent(e);
}
for (ActivityInfoWithEventsDocument aweDoc : docBuilder.getActivitiesWithEvents()) {
for (ActivityRecoveryDAO recovery : recoveries) {
if (String.valueOf(recovery.getActivityId()).equals(aweDoc.getActivityInfoDoc().getActivityInfo().getAiid())) {
TFailureInfo failure = aweDoc.getActivityInfoDoc().getActivityInfo().addNewFailure();
failure.setReason(recovery.getReason());
failure.setDtFailure(toCalendar(recovery.getDateTime()));
failure.setActions(recovery.getActions());
failure.setRetries(recovery.getRetries());
aweDoc.getActivityInfoDoc().getActivityInfo().setStatus(TActivityStatus.FAILURE);
}
}
ActivityInfoWithEventsType activityWE = new ActivityInfoWithEventsType();
TActivityInfo actInfoDoc = aweDoc.getActivityInfoDoc().getActivityInfo();
TEventInfoList evtInfoList = aweDoc.getEventInfoList().getEventInfoList();
// add activityInfo
// add event info
ActivityInfoType activity = fillActivityInfo(new ActivityInfoType(), actInfoDoc);
/*XmlOptions opt = new XmlOptions();
opt = opt.setSaveOuter();*/
EventInfoList eventList = fillEventInfo(new EventInfoList(), evtInfoList);
activityWE.setActivityInfo(activity);
activityWE.setActivityEventsList(eventList);
activitiesWithEvents.addActivityInfoWithEvents(activityWE);
}
return activitiesWithEvents;
}
Aggregations