Java Code Examples for org.slf4j.MDC#putCloseable()
The following examples show how to use
org.slf4j.MDC#putCloseable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationSchemaServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override public void upgradeCas(CAS aCas, SourceDocument aSourceDocument, String aUser) throws UIMAException, IOException { upgradeCas(aCas, aSourceDocument.getProject()); try (MDC.MDCCloseable closable = MDC.putCloseable( Logging.KEY_PROJECT_ID, String.valueOf(aSourceDocument.getProject().getId()))) { Project project = aSourceDocument.getProject(); log.info( "Upgraded CAS of user [{}] for " + "document [{}]({}) in project [{}]({})", aUser, aSourceDocument.getName(), aSourceDocument.getId(), project.getName(), project.getId()); } }
Example 2
Source File: AnnotationSchemaServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override @Transactional public void createLayer(AnnotationLayer aLayer) { if (isNull(aLayer.getId())) { entityManager.persist(aLayer); } else { entityManager.merge(aLayer); } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aLayer.getProject().getId()))) { Project project = aLayer.getProject(); log.info("Created layer [{}]({}) in project [{}]({})", aLayer.getName(), aLayer.getId(), project.getName(), project.getId()); } }
Example 3
Source File: AnnotationSchemaServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override @Transactional public void createTagSet(TagSet aTagSet) { if (isNull(aTagSet.getId())) { entityManager.persist(aTagSet); } else { entityManager.merge(aTagSet); } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aTagSet.getProject().getId()))) { Project project = aTagSet.getProject(); log.info("Created tagset [{}]({}) in project [{}]({})", aTagSet.getName(), aTagSet.getId(), project.getName(), project.getId()); } }
Example 4
Source File: ConstraintsServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
/** * Provides exporting constraints as a file. */ @Override public File exportConstraintAsFile(ConstraintSet aSet) { String constraintRulesPath = repositoryProperties.getPath().getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aSet.getProject().getId() + "/" + ConstraintsService.CONSTRAINTS + "/"; String filename = aSet.getId() + ".txt"; File constraintsFile = new File(constraintRulesPath, filename); if (constraintsFile.exists()) { try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSet.getProject().getId()))) { log.info("Exported constraints set [{}] from project [{}]({})", aSet.getName(), aSet.getProject().getName(), aSet.getProject().getId()); } return constraintsFile; } else { try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSet.getProject().getId()))) { log.info("Unable to read constraints set file [{}] in project [{}]({})", filename, aSet.getProject().getName(), aSet.getProject().getId()); } return null; } }
Example 5
Source File: ConstraintsServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override public void writeConstraintSet(ConstraintSet aSet, InputStream aContent) throws IOException { String constraintRulesPath = repositoryProperties.getPath().getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aSet.getProject().getId() + "/" + ConstraintsService.CONSTRAINTS + "/"; String filename = aSet.getId() + ".txt"; FileUtils.forceMkdir(new File(constraintRulesPath)); FileUtils.copyInputStreamToFile(aContent, new File(constraintRulesPath, filename)); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSet.getProject().getId()))) { log.info("Saved constraints set [{}] in project [{}]({})", aSet.getName(), aSet.getProject().getName(), aSet.getProject().getId()); } }
Example 6
Source File: ConstraintsServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override public String readConstrainSet(ConstraintSet aSet) throws IOException { String constraintRulesPath = repositoryProperties.getPath().getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aSet.getProject().getId() + "/" + ConstraintsService.CONSTRAINTS + "/"; String filename = aSet.getId() + ".txt"; String data; try (BOMInputStream is = new BOMInputStream( new FileInputStream(new File(constraintRulesPath, filename)))) { data = IOUtils.toString(is, "UTF-8"); } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSet.getProject().getId()))) { log.info("Read constraints set [{}] in project [{}]({})", aSet.getName(), aSet.getProject().getName(), aSet.getProject().getId()); } return data; }
Example 7
Source File: ProjectServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override @Transactional public void createProject(Project aProject) throws IOException { if (aProject.getId() != null) { throw new IllegalArgumentException("Project has already been created before."); } aProject.setCreated(new Date()); entityManager.persist(aProject); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) { log.info("Created project [{}]({})", aProject.getName(), aProject.getId()); } String path = repositoryProperties.getPath().getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aProject.getId(); FileUtils.forceMkdir(new File(path)); applicationEventPublisher.publishEvent(new AfterProjectCreatedEvent(this, aProject)); }
Example 8
Source File: DocumentServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override @Transactional public void createAnnotationDocument(AnnotationDocument aAnnotationDocument) { Validate.notNull(aAnnotationDocument, "Annotation document must be specified"); if (isNull(aAnnotationDocument.getId())) { entityManager.persist(aAnnotationDocument); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aAnnotationDocument.getProject().getId()))) { log.info( "Created annotation document [{}] for user [{}] for source document " + "[{}]({}) in project [{}]({})", aAnnotationDocument.getId(), aAnnotationDocument.getUser(), aAnnotationDocument.getDocument().getName(), aAnnotationDocument.getDocument().getId(), aAnnotationDocument.getProject().getName(), aAnnotationDocument.getProject().getId()); } } else { entityManager.merge(aAnnotationDocument); } }
Example 9
Source File: CurationDocumentServiceImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override public void removeCurationDocumentContent(SourceDocument aSourceDocument, String aUsername) throws IOException { if (new File(casStorageService.getAnnotationFolder(aSourceDocument), WebAnnoConst.CURATION_USER + ".ser").exists()) { FileUtils.forceDelete(new File(casStorageService.getAnnotationFolder(aSourceDocument), WebAnnoConst.CURATION_USER + ".ser")); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSourceDocument.getProject().getId()))) { Project project = aSourceDocument.getProject(); log.info("Removed curation of source document [{}]({}) from project [{}]({})", aSourceDocument.getName(), aSourceDocument.getId(), project.getName(), project.getId()); } } }
Example 10
Source File: WeblichtChainServiceImpl.java From inception with Apache License 2.0 | 6 votes |
@Override @Transactional public void deleteChain(WeblichtChain aChain) throws IOException { entityManager.remove( entityManager.contains(aChain) ? aChain : entityManager.merge(aChain)); File gaz = getChainFile(aChain); if (gaz.exists()) { gaz.delete(); } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aChain.getRecommender().getProject().getId()))) { log.info("Removed chain [{}] from recommender [{}]({}) in project [{}]({})", aChain.getName(), aChain.getRecommender().getName(), aChain.getRecommender().getId(), aChain.getRecommender().getProject().getName(), aChain.getRecommender().getProject().getId()); } }
Example 11
Source File: ProjectServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
@Override @Transactional public void createProjectPermission(ProjectPermission aPermission) { entityManager.persist(aPermission); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aPermission.getProject().getId()))) { log.info("Created permission [{}] for user [{}] on project [{}]({})", aPermission.getLevel(), aPermission.getUser(), aPermission.getProject().getName(), aPermission.getProject().getId()); } }
Example 12
Source File: ProjectServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
@Override @Transactional public void removeProject(Project aProject) throws IOException { long start = System.currentTimeMillis(); // remove metadata from DB Project project = aProject; if (!entityManager.contains(project)) { project = entityManager.merge(project); } applicationEventPublisher.publishEvent(new BeforeProjectRemovedEvent(this, aProject)); for (ProjectPermission permissions : getProjectPermissions(aProject)) { entityManager.remove(permissions); } entityManager.remove(project); // remove the project directory from the file system String path = repositoryProperties.getPath().getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aProject.getId(); try { FastIOUtils.delete(new File(path)); } catch (FileNotFoundException e) { try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) { log.info("Project directory to be deleted was not found: [{}]. Ignoring.", path); } } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) { log.info("Removed project [{}]({}) ({})", aProject.getName(), aProject.getId(), formatDurationWords(System.currentTimeMillis() - start, true, true)); } }
Example 13
Source File: WeblichtChainServiceImpl.java From inception with Apache License 2.0 | 5 votes |
@Override @Transactional public void createOrUpdateChain(WeblichtChain aGazeteer) { if (aGazeteer.getId() == null) { entityManager.persist(aGazeteer); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aGazeteer.getRecommender().getProject().getId()))) { log.info("Created chain [{}] for recommender [{}]({}) in project [{}]({})", aGazeteer.getName(), aGazeteer.getRecommender().getName(), aGazeteer.getRecommender().getId(), aGazeteer.getRecommender().getProject().getName(), aGazeteer.getRecommender().getProject().getId()); } } else { entityManager.merge(aGazeteer); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aGazeteer.getRecommender().getProject().getId()))) { log.info("Updated chain [{}] for recommender [{}]({}) in project [{}]({})", aGazeteer.getName(), aGazeteer.getRecommender().getName(), aGazeteer.getRecommender().getId(), aGazeteer.getRecommender().getProject().getName(), aGazeteer.getRecommender().getProject().getId()); } } }
Example 14
Source File: ProjectServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
@Override @Transactional public void removeProjectPermission(ProjectPermission aPermission) { entityManager.remove(aPermission); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aPermission.getProject().getId()))) { log.info("Removed permission [{}] for user [{}] on project [{}]({})", aPermission.getLevel(), aPermission.getUser(), aPermission.getProject().getName(), aPermission.getProject().getId()); } }
Example 15
Source File: DocumentServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
@Override @Transactional public void removeSourceDocument(SourceDocument aDocument) throws IOException { Validate.notNull(aDocument, "Source document must be specified"); // BeforeDocumentRemovedEvent is triggered first, since methods that rely // on it might need to have access to the associated annotation documents applicationEventPublisher.publishEvent(new BeforeDocumentRemovedEvent(this, aDocument)); for (AnnotationDocument annotationDocument : listAllAnnotationDocuments(aDocument)) { removeAnnotationDocument(annotationDocument); } entityManager.remove( entityManager.contains(aDocument) ? aDocument : entityManager.merge(aDocument)); String path = repositoryProperties.getPath().getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aDocument.getProject().getId() + "/" + DOCUMENT_FOLDER + "/" + aDocument.getId(); // remove from file both source and related annotation file if (new File(path).exists()) { FileUtils.forceDelete(new File(path)); } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) { Project project = aDocument.getProject(); log.info("Removed source document [{}]({}) from project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId()); } }
Example 16
Source File: AnnotationSchemaServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
@Override public void upgradeCas(CAS aCas, SourceDocument aSourceDocument, String aUser, CasUpgradeMode aMode) throws UIMAException, IOException { switch (aMode) { case NO_CAS_UPGRADE: return; case AUTO_CAS_UPGRADE: { boolean upgraded = upgradeCasIfRequired(aCas, aSourceDocument); if (!upgraded) { try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSourceDocument.getProject().getId()))) { log.debug( "CAS of user [{}] for document [{}]({}) in project [{}]({}) is already " + "compatible with project type system - skipping upgrade", aUser, aSourceDocument.getName(), aSourceDocument.getId(), aSourceDocument.getProject().getName(), aSourceDocument.getProject().getId()); } } return; } case FORCE_CAS_UPGRADE: upgradeCas(aCas, aSourceDocument, aUser); return; } }
Example 17
Source File: MDCUtil.java From styx with Apache License 2.0 | 5 votes |
public static MDC.MDCCloseable safePutCloseable(String key, String value) { try { return MDC.putCloseable(key, value); } catch (Exception e) { log.error("Failed to put MDC", e); // Returning null here is ok as try-with-resources ignores null resources. return null; } }
Example 18
Source File: OpenIdConnectServlet.java From vipps-developers with MIT License | 5 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String[] pathParts; if(req.getPathInfo() != null){ pathParts = req.getPathInfo().split("/"); }else{ pathParts = req.getServletPath().split("/"); } if (pathParts.length < 2) { resp.sendError(404); return; } try (MDC.MDCCloseable ignored = MDC.putCloseable("provider", req.getServletPath())) { String action = pathParts[1]; if (action.equals("authenticate")) { authenticate(req, resp); } else if (action.equals("callback")) { oauth2callback(req, resp); } else if (action.equals("token")) { getToken(req, resp); } else if (action.equals("session")) { setupSession(req, resp); }else if (action.equals("logout")) { logoutSession(req, resp); } else { logger.warn("Unknown request {}", req.getServletPath() + req.getPathInfo() + "?" + req.getQueryString()); resp.sendError(404); } } }
Example 19
Source File: AnnotationSchemaServiceImpl.java From webanno with Apache License 2.0 | 5 votes |
@Override @Transactional public void createTag(Tag aTag) { if (isNull(aTag.getId())) { entityManager.persist(aTag); if (applicationEventPublisher != null) { applicationEventPublisher.publishEvent(new TagCreatedEvent(this, aTag)); } } else { entityManager.merge(aTag); if (applicationEventPublisher != null) { applicationEventPublisher.publishEvent(new TagUpdatedEvent(this, aTag)); } } try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aTag.getTagSet().getProject().getId()))) { TagSet tagset = aTag.getTagSet(); Project project = tagset.getProject(); log.info("Created tag [{}]({}) in tagset [{}]({}) in project [{}]({})", aTag.getName(), aTag.getId(), tagset.getName(), tagset.getId(), project.getName(), project.getId()); } }
Example 20
Source File: ImportExportServiceImpl.java From webanno with Apache License 2.0 | 4 votes |
@Override @Transactional public File exportAnnotationDocument(SourceDocument aDocument, String aUser, FormatSupport aFormat, String aFileName, Mode aMode, boolean aStripExtension, Map<Pair<Project, String>, Object> aBulkOperationContext) throws UIMAException, IOException, ClassNotFoundException { Map<Pair<Project, String>, Object> bulkOperationContext = aBulkOperationContext; if (bulkOperationContext == null) { bulkOperationContext = new HashMap<>(); } String username; // for Correction, it will export the corrected document (of the logged in user) // (CORRECTION_USER.ser is the automated result displayed for the user to correct it, not // the final result) for automation, it will export either the corrected document // (Annotated) or the automated document if (aMode.equals(ANNOTATION) || aMode.equals(AUTOMATION) || aMode.equals(CORRECTION)) { username = aUser; } // The merge result will be exported else { username = CURATION_USER; } // Read file File exportFile; try (CasStorageSession session = CasStorageSession.openNested()) { CAS cas = casStorageService.readCas(aDocument, username); exportFile = exportCasToFile(cas, aDocument, aFileName, aFormat, aStripExtension, aBulkOperationContext); } Project project = aDocument.getProject(); try (MDC.MDCCloseable closable = MDC.putCloseable(KEY_PROJECT_ID, String.valueOf(project.getId()))) { log.info("Exported annotations [{}]({}) for user [{}] from project [{}]({}) " + "using format [{}]", aDocument.getName(), aDocument.getId(), aUser, project.getName(), project.getId(), aFormat.getId()); } return exportFile; }