use of com.bluenimble.platform.db.Database.ExchangeOption in project serverless by bluenimble.
the class ExportDatabaseSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String[] aEntities = Lang.split((String) request.get(Spec.Entities), Lang.COMMA, true);
Set<String> entities = null;
if (aEntities != null && aEntities.length > 0) {
entities = new HashSet<String>();
for (String entity : aEntities) {
entities.add(entity.toUpperCase());
}
}
String[] aOptions = Lang.split((String) request.get(Spec.Options), Lang.COMMA, true);
Map<ExchangeOption, Boolean> options = null;
if (aOptions != null && aOptions.length > 0) {
for (String o : aOptions) {
try {
options.put(ExchangeOption.valueOf(o.toLowerCase()), true);
} catch (Exception ex) {
// ignore malformed options
}
}
}
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
String file = (String) request.get(Spec.File) + DotGz;
JsonObject result = new JsonObject();
result.set(Spec.File, file);
final StringBuilder sb = new StringBuilder();
try {
space.feature(Database.class, provider, request).exp(entities, space.feature(Storage.class, provider, request).root().get(file).writer(request), options, new Database.ExchangeListener() {
@Override
public void onMessage(String message) {
sb.append(message).append(Lang.ENDLN);
}
});
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
result.set(Output.Feedback, sb.toString());
sb.setLength(0);
return new JsonApiOutput(result);
}
use of com.bluenimble.platform.db.Database.ExchangeOption in project serverless by bluenimble.
the class ImportDatabaseSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String[] aEntities = Lang.split((String) request.get(Spec.Entities), Lang.COMMA, true);
Set<String> entities = null;
if (aEntities != null && aEntities.length > 0) {
entities = new HashSet<String>();
for (String entity : aEntities) {
entities.add(entity.toUpperCase());
}
}
String[] aOptions = Lang.split((String) request.get(Spec.Options), Lang.COMMA, true);
Map<ExchangeOption, Boolean> options = null;
if (aOptions != null && aOptions.length > 0) {
for (String o : aOptions) {
try {
options.put(ExchangeOption.valueOf(o.toLowerCase()), true);
} catch (Exception ex) {
// ignore malformed options
}
}
}
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
String file = (String) request.get(Spec.File);
JsonObject result = new JsonObject();
result.set(Spec.File, file);
final StringBuilder sb = new StringBuilder();
try {
space.feature(Database.class, provider, request).imp(entities, space.feature(Storage.class, provider, request).root().get(file).reader(request), options, new Database.ExchangeListener() {
@Override
public void onMessage(String message) {
sb.append(message).append(Lang.ENDLN);
}
});
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
result.set(Output.Feedback, sb.toString());
sb.setLength(0);
return new JsonApiOutput(result);
}
Aggregations