import io.github.ibuildthecloud.gdapi.request.ApiRequest; //導入方法依賴的package包/類
@Override
public void handle(ApiRequest request) throws IOException {
if (ApiContext.getContext().getPolicy() != null) {
return;
}
if (ApiContext.getContext().getTransformationService() == null){
ApiContext.getContext().setTransformationService(transformationService);
}
Account authenticatedAsAccount = getAccount(request);
if (authenticatedAsAccount == null ||
!accountDao.isActiveAccount(authenticatedAsAccount)) {
throw new ClientVisibleException(ResponseCodes.UNAUTHORIZED);
}
Set identities = getIdentities(authenticatedAsAccount);
if (identities == null || identities.size() == 0) {
throw new ClientVisibleException(ResponseCodes.UNAUTHORIZED);
}
Account account = getAccountRequested(authenticatedAsAccount, identities, request);
Policy policy = getPolicy(account, authenticatedAsAccount, identities, request);
if (policy == null) {
log.error("Failed to find policy for [{}]", account.getId());
throwUnauthorized();
}
SchemaFactory schemaFactory = getSchemaFactory(account, policy, request);
if (schemaFactory == null) {
log.error("Failed to find a schema for account type [{}]", account.getKind());
if (SecurityConstants.SECURITY.get()) {
throwUnauthorized();
}
} else if (request.getType() != null && request.getType().endsWith("s")) {
//In case the SchemaFactory didn't have the type before.
//we need to make it singular.
String singleType = schemaFactory.getSingularName(request.getType());
if (singleType != null) {
request.setType(singleType);
}
}
saveInContext(request, policy, schemaFactory);
}