Search in sources :

Example 6 with ProgrammingErrorException

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);
    }
}
Also used : MasterList(net.geoprism.registry.MasterList) JobHistory(com.runwaysdk.system.scheduler.JobHistory) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) JSONException(org.json.JSONException) MasterListVersion(net.geoprism.registry.MasterListVersion) GeoprismUser(net.geoprism.GeoprismUser) SimpleDateFormat(java.text.SimpleDateFormat) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 7 with ProgrammingErrorException

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();
    }
}
Also used : Locale(java.util.Locale) Cookie(javax.servlet.http.Cookie) RedirectResponse(com.runwaysdk.mvc.RedirectResponse) JsonObject(com.google.gson.JsonObject) ClientRequestIF(com.runwaysdk.constants.ClientRequestIF) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) WebClientSession(com.runwaysdk.web.WebClientSession) JsonArray(com.google.gson.JsonArray) JSONObject(org.json.JSONObject) SessionController(net.geoprism.SessionController) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 8 with ProgrammingErrorException

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);
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) FhirContext(ca.uhn.fhir.context.FhirContext) Organization(org.hl7.fhir.r4.model.Organization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Binary(org.hl7.fhir.r4.model.Binary) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IParser(ca.uhn.fhir.parser.IParser) IIdType(org.hl7.fhir.instance.model.api.IIdType) Location(org.hl7.fhir.r4.model.Location)

Example 9 with ProgrammingErrorException

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);
    }
}
Also used : FhirSyncLevel(net.geoprism.registry.etl.FhirSyncLevel) ListTypeVersion(net.geoprism.registry.ListTypeVersion) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) IOException(java.io.IOException) HttpError(net.geoprism.registry.etl.export.HttpError) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage)

Example 10 with ProgrammingErrorException

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);
    }
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) Bundle(org.hl7.fhir.r4.model.Bundle) FileWriter(java.io.FileWriter) IOException(java.io.IOException) FhirExternalSystem(net.geoprism.registry.graph.FhirExternalSystem) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) IOException(java.io.IOException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) HttpError(net.geoprism.registry.etl.export.HttpError) File(java.io.File) IParser(ca.uhn.fhir.parser.IParser)

Aggregations

ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)67 IOException (java.io.IOException)34 SimpleDateFormat (java.text.SimpleDateFormat)21 JsonObject (com.google.gson.JsonObject)18 File (java.io.File)16 ParseException (java.text.ParseException)16 InputStream (java.io.InputStream)13 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)13 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)12 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)11 JSONException (org.json.JSONException)11 JsonArray (com.google.gson.JsonArray)10 List (java.util.List)10 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)8