use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class FhirExportJob method toJson.
public JsonObject toJson() {
SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
final MasterListVersion version = this.getVersion();
final MasterList masterlist = version.getMasterlist();
final ServerGeoObjectType type = masterlist.getGeoObjectType();
final JobHistory history = this.getAllJobHistory().getAll().get(0);
final GeoprismUser user = GeoprismUser.get(this.getRunAsUser().getOid());
try {
final JsonObject object = new JsonObject();
object.addProperty(FhirExportJob.OID, this.getOid());
object.add(FhirExportJob.VERSION, this.getVersion().toJSON(false));
object.addProperty(FhirExportJob.IMPLEMENTATION, this.getImplementation());
object.addProperty(FhirExportJob.TYPE, type.getLabel().getValue());
object.addProperty(JobHistory.STATUS, history.getStatus().get(0).getDisplayLabel());
object.addProperty("date", format.format(version.getPublishDate()));
object.addProperty("author", user.getUsername());
object.addProperty("createDate", format.format(history.getCreateDate()));
object.addProperty("lastUpdateDate", format.format(history.getLastUpdateDate()));
object.addProperty("workProgress", history.getWorkProgress());
object.addProperty("workTotal", history.getWorkTotal());
object.addProperty("historyoryId", history.getOid());
if (history.getErrorJson() != null && history.getErrorJson().length() > 0) {
object.addProperty("message", history.getLocalizedError(Session.getCurrentLocale()));
}
return object;
} catch (JSONException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class RegistrySessionController method ologin.
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON)
public ResponseIF ologin(ServletRequestIF req, @RequestParamter(name = "code", required = true) String code, @RequestParamter(name = "state", required = true) String state) throws MalformedURLException, JSONException {
final SessionController geoprism = new SessionController();
// URL url = new URL(req.getScheme(), req.getServerName(), req.getServerPort(), req.getContextPath());
//
// String redirect = url.toString();
JSONObject stateObject = new JSONObject(state);
String serverId = stateObject.getString(OauthServerIF.SERVER_ID);
Locale[] locales = geoprism.getLocales(req);
WebClientSession clientSession = WebClientSession.createAnonymousSession(locales);
try {
ClientRequestIF clientRequest = clientSession.getRequest();
String cgrSessionJsonString = RegistrySessionServiceDTO.ologin(clientRequest, serverId, code, LocaleSerializer.serialize(locales), null);
JsonObject cgrSessionJson = (JsonObject) JsonParser.parseString(cgrSessionJsonString);
final String sessionId = cgrSessionJson.get("sessionId").getAsString();
final String username = cgrSessionJson.get("username").getAsString();
geoprism.createSession(req, sessionId, locales);
clientRequest = (ClientRequestIF) req.getAttribute(ClientConstants.CLIENTREQUEST);
JsonArray roles = (JsonArray) JsonParser.parseString(RoleViewDTO.getCurrentRoles(clientRequest));
JsonArray roleDisplayLabels = (JsonArray) JsonParser.parseString(RoleViewDTO.getCurrentRoleDisplayLabels(clientRequest));
JsonObject cookieJson = new JsonObject();
cookieJson.addProperty("loggedIn", clientRequest.isLoggedIn());
cookieJson.add("roles", roles);
cookieJson.add("roleDisplayLabels", roleDisplayLabels);
cookieJson.addProperty("userName", username);
cookieJson.addProperty("version", ClientConfigurationService.getServerVersion());
// final Locale sessionLocale = Session.getCurrentLocale();
//
// JsonArray installedLocalesArr = new JsonArray();
// Set<SupportedLocaleIF> installedLocales = LocalizationFacade.getSupportedLocales();
// for (SupportedLocaleIF supportedLocale : installedLocales)
// {
// Locale locale = supportedLocale.getLocale();
//
// JsonObject locObj = new JsonObject();
// locObj.addProperty("language", locale.getDisplayLanguage(sessionLocale));
// locObj.addProperty("country", locale.getDisplayCountry(sessionLocale));
// locObj.addProperty("name", locale.getDisplayName(sessionLocale));
// locObj.addProperty("variant", locale.getDisplayVariant(sessionLocale));
//
// installedLocalesArr.add(locObj);
// }
JsonArray jaLocales = ServiceFactory.getRegistryService().getLocales(clientRequest.getSessionId());
cookieJson.add("installedLocales", jaLocales);
final String cookieValue = URLEncoder.encode(cookieJson.toString(), "UTF-8");
Cookie cookie = new Cookie("user", cookieValue);
cookie.setMaxAge(-1);
RedirectResponse response = new RedirectResponse("/");
response.addCookie(cookie);
return response;
} catch (Throwable t) {
Locale locale = CommonProperties.getDefaultLocale();
if (locales.length > 0) {
locale = locales[0];
}
String errorMessage = RunwayException.localizeThrowable(t, locale);
try {
errorMessage = URLEncoder.encode(errorMessage, StandardCharsets.UTF_8.name());
} catch (Throwable t2) {
throw new ProgrammingErrorException(t2);
}
RedirectResponse response = new RedirectResponse("/cgr/manage#/login/" + errorMessage);
return response;
} finally {
clientSession.logout();
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class FhirBulkDataImporter method synchronize.
public void synchronize() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
CloseableHttpClient myClient = builder.build();
FhirContext ctx = FhirContext.forR4();
String statusUrl = initiateBulkExport(myClient, ctx);
if (statusUrl != null) {
final List<String> outputs = getExportResults(myClient, statusUrl);
IGenericClient client = ctx.newRestfulGenericClient(this.system.getUrl());
for (String binaryUrl : outputs) {
Binary binary = client.fetchResourceFromUrl(Binary.class, binaryUrl);
String base64 = binary.getContentAsBase64();
byte[] result = Base64.getDecoder().decode(base64);
IParser parser = ctx.newJsonParser();
String message = new String(result);
try (BufferedReader reader = new BufferedReader(new StringReader(message))) {
String line = null;
while ((line = reader.readLine()) != null) {
IBaseResource resource = parser.parseResource(line);
IIdType id = resource.getIdElement();
String resourceType = id.getResourceType();
if (resourceType.equals(ResourceTypes.LOCATION.toCode())) {
Location location = (Location) resource;
this.processor.process(location);
} else if (resourceType.equals(ResourceTypes.ORGANIZATION.toCode())) {
Organization organization = (Organization) resource;
this.processor.process(organization);
}
}
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class FhirExportSynchronizationManager method synchronize.
public void synchronize() {
final FhirExternalSystem system = (FhirExternalSystem) this.config.getSystem();
try (FhirConnection connection = FhirConnectionFactory.get(system)) {
SortedSet<FhirSyncLevel> levels = this.config.getLevels();
int expectedLevel = 0;
long exportCount = 0;
for (FhirSyncLevel level : levels) {
if (level.getLevel() != expectedLevel) {
throw new ProgrammingErrorException("Unexpected level number [" + level.getLevel() + "].");
}
history.appLock();
history.setWorkProgress((long) expectedLevel);
history.setExportedRecords(exportCount);
history.apply();
ListTypeVersion version = ListTypeVersion.get(level.getVersionId());
FhirDataPopulator populator = FhirFactory.getPopulator(level.getImplementation());
ListTypeFhirExporter exporter = new ListTypeFhirExporter(version, connection, populator, true);
long results = exporter.export();
exportCount += results;
expectedLevel++;
}
history.appLock();
history.setWorkTotal((long) expectedLevel);
history.setWorkProgress((long) expectedLevel);
history.setExportedRecords(exportCount);
history.clearStage();
history.addStage(ExportStage.COMPLETE);
history.apply();
NotificationFacade.queue(new GlobalNotificationMessage(MessageType.DATA_EXPORT_JOB_CHANGE, null));
handleExportErrors();
} catch (Exception e) {
throw new HttpError(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class FhirExportSynchronizationManager method writeToFile.
public File writeToFile() throws IOException {
final FhirExternalSystem system = (FhirExternalSystem) this.config.getSystem();
try (FhirConnection connection = FhirConnectionFactory.get(system)) {
String name = SessionPredicate.generateId();
File root = new File(new File(VaultProperties.getPath("vault.default"), "files"), name);
root.mkdirs();
Bundle bundle = this.generateBundle(connection);
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
try {
parser.encodeResourceToWriter(bundle, new FileWriter(new File(root, "bundle.json")));
} catch (DataFormatException | IOException e) {
throw new ProgrammingErrorException(e);
}
return root;
} catch (Exception e) {
throw new HttpError(e);
}
}
Aggregations