List of usage examples for org.apache.commons.logging Log warn
void warn(Object message);
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.NamedEntityTaskManager.java
/** * Aggregates and sets final judgments in the JCases provided by documentsJCas. * * @param jobID2 the job ID.//from w w w .j a va 2 s. com * @param documentsJCas the documents. * @throws IOException hum? * @throws UnsupportedEncodingException hum? * @throws CrowdException hum? */ public void setCrowdJobAnnotationsInDocs(String jobID2, List<JCas> documentsJCas) throws UnsupportedEncodingException, IOException, CrowdException { omittedEntities = 0; Log LOG = LogFactory.getLog(getClass()); BufferedReader br = getReaderForRawJudgments(jobID2); String line; // Jackson JSON object mapper ObjectMapper mapper = new ObjectMapper(); // Maps our own token offsets (needed by JS in the crowdflower task) to Jcas offsets // One map for start and end offset conversion each and new mappings for each document (to be able to use multiple documents) // Array position is token number List<List<Integer>> charStartMappings = new ArrayList<List<Integer>>(); List<List<Integer>> charEndMappings = new ArrayList<List<Integer>>(); for (JCas cas : documentsJCas) { List<Integer> charStartMapping = new ArrayList<Integer>(); List<Integer> charEndMapping = new ArrayList<Integer>(); for (Sentence sentence : select(cas, Sentence.class)) { for (Token token : selectCovered(Token.class, sentence)) { charStartMapping.add(token.getBegin()); charEndMapping.add(token.getEnd()); } } charStartMappings.add(charStartMapping); charEndMappings.add(charEndMapping); } while ((line = br.readLine()) != null) { // Try to process each line, omit data if an error occurs try { JsonNode elem = mapper.readTree(line); // Document string contains one char to specify type (golden vs. not golden) // and a new number starting at 0 for each new document int documentNo = Integer .valueOf(elem.path(JSON_FIELD_DATA).path(JSON_FIELD_DOCUMENT).getTextValue().substring(1)); if (documentNo >= documentsJCas.size()) { throw new CrowdException( "Error, number of documents changed from first upload! Tried to access document: " + documentNo); } //Only process elements that are finalized, i.e. elements that don't have missing judgments String state = elem.path(JSON_FIELD_STATE).getTextValue(); if (state.equals(JSON_FIELD_FINALIZED)) { JCas cas = documentsJCas.get(documentNo); String typeExplicit = elem.path(JSON_FIELD_RESULTS) .path(NamedEntityTask2Data.FIELD_TODECIDE_RESULT).path(JSON_FIELD_AGGREGATED) .getTextValue(); String type = ne2TaskMap.get(typeExplicit); //Type is null when it is not in ne2TaskMap. //These are usually difficult cases where workers are unsure or where a wrong word has been marked in task1 if (type == null) { //We can simply skip any such cases continue; } String posText = elem.path(JSON_FIELD_DATA).path(NamedEntityTask2Data.FIELD_POSTEXT) .getTextValue(); int offset = 0; // Element numbering in Crowdflower judgments can be different than token numbering in the Cas, // to support an always incrementing numbering in a multi-document setting for displayed spans (task1) // docOffset is the diff of the marker (saved from task1 and also present in task2 data) // to token numbering of the Cas for the current document if (!elem.path(JSON_FIELD_DATA).path(NamedEntityTask2Data.FIELD_DOCOFFSET).isMissingNode()) { offset = elem.path(JSON_FIELD_DATA).path(NamedEntityTask2Data.FIELD_DOCOFFSET) .getIntValue(); } JsonNode marker = mapper.readTree(posText); int start = marker.path(JSON_FIELD_START_MARKER).getIntValue(); int end = marker.path(JSON_FIELD_END_MARKER).getIntValue(); //Map named entity to character offsets and add it to the Cas NamedEntity newEntity = new NamedEntity(cas, charStartMappings.get(documentNo).get(start - offset), charEndMappings.get(documentNo).get(end - offset)); newEntity.setValue(type); newEntity.addToIndexes(); } } //We catch all exceptions here, in order to guarantee best effort in processing the data. //That is, we try to assign to every sentence and don't stop if there is a problem and inform the user afterwards. catch (Exception e) { omittedEntities++; LOG.warn("Warning, omitted a sentence from task2 import because of an error in processing it: " + e.getMessage()); e.printStackTrace(); } } }
From source file:org.acmsl.queryj.api.AbstractTemplateGeneratorThread.java
/** * Runs the template generation process. * @param templateGenerator the template generator. * @param template the template.// w w w . j av a2s. c o m * @param outputDir the output folder. * @param rootFolder the root folder. * @param charset the {@link Charset} to use. * @param threadIndex the thread index. * @param barrier the cyclic barrier. * @param log the {@link Log} instance. */ @ThreadSafe protected void runGenerator(@NotNull final TG templateGenerator, @NotNull final T template, @NotNull final File outputDir, @NotNull final File rootFolder, @NotNull final Charset charset, final int threadIndex, @Nullable final CyclicBarrier barrier, @Nullable final Log log) { boolean generated = false; try { generated = templateGenerator.write(template, outputDir, rootFolder, charset); } catch (@NotNull final QueryJBuildException unknownException) { if (log != null) { log.warn(unknownException); } } catch (@NotNull final IOException ioException) { if (log != null) { log.warn(ioException); } } if (generated) { if (log != null) { log.debug(buildSuccessLogMessage(template, threadIndex)); } } if (barrier != null) { try { barrier.await(); } catch (@NotNull final InterruptedException interrupted) { if (log != null) { log.debug("Interrupted thread", interrupted); } Thread.currentThread().interrupt(); } catch (@NotNull final BrokenBarrierException brokenBarrier) { if (log != null) { log.warn(AbstractTemplateWritingHandler.BROKEN_BARRIER_LITERAL, brokenBarrier); } } } }
From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.ReportMissingPropertiesHandler.java
/** * Reports any undeclared property./*from w ww.j a v a 2 s . c o m*/ * @param properties the declared properties. * @param columns the properties from the result set. * @param sql the query itself. * @param log the log. */ protected void diagnoseMissingProperties(@NotNull final List<Property<String>> properties, @NotNull final List<Property<String>> columns, @NotNull final Sql<String> sql, @Nullable final Log log) { if (log != null) { @NotNull final List<Property<String>> t_lMissingProperties = detectMissingProperties(properties, columns); int t_iIndex = 1; for (@Nullable final Property<String> t_MissingProperty : t_lMissingProperties) { if (t_MissingProperty != null) { log.warn("Column not declared (" + t_iIndex + ", " + t_MissingProperty.getColumnName() + ", " + t_MissingProperty.getType() + "), in sql " + sql.getId()); } t_iIndex++; } } }
From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.ReportMissingPropertiesHandlerTest.java
/** * Checks whether it detects missing properties. * Throws QueryJBuildException/*from w w w . j av a 2 s .c o m*/ */ @Test public void detects_missing_properties() throws QueryJBuildException { @NotNull final Log t_Log = EasyMock.createNiceMock(Log.class); @NotNull final ReportMissingPropertiesHandler instance = new ReportMissingPropertiesHandler() { /** * {@inheritDoc} */ @Nullable @Override protected Log retrieveLog() { return t_Log; } }; @NotNull final QueryJCommand t_Parameters = new ConfigurationQueryJCommandImpl( new SerializablePropertiesConfiguration()); @NotNull final List<Property<String>> t_lProperties = new ArrayList<>(2); t_lProperties.add(new PropertyElement<>("name", "name", 1, String.class.getSimpleName(), false)); t_lProperties.add(new PropertyElement<>("tmst", "tmst", 2, "Date", false)); @NotNull final List<Property<String>> t_lColumns = new ArrayList<>(3); t_lColumns.add(new PropertyElement<>("name", "name", 1, String.class.getSimpleName(), false)); t_lColumns.add(new PropertyElement<>("tmst", "tmst", 2, "Date", false)); t_lColumns.add(new PropertyElement<>("flag", "flg", 3, int.class.getSimpleName(), false)); @NotNull final Sql<String> t_Sql = new SqlElement<>("id", "dao", "name", "String", SqlCardinality.SINGLE, "all", true, false, "description"); new QueryJCommandWrapper<List<Property<String>>>(t_Parameters) .setSetting(RetrieveResultPropertiesHandler.CURRENT_PROPERTIES, t_lProperties); new QueryJCommandWrapper<List<Property<String>>>(t_Parameters) .setSetting(RetrieveResultSetColumnsHandler.CURRENT_COLUMNS, t_lColumns); new QueryJCommandWrapper<Sql<String>>(t_Parameters).setSetting(RetrieveQueryHandler.CURRENT_SQL, t_Sql); t_Log.warn(EasyMock.anyObject()); EasyMock.expectLastCall(); EasyMock.replay(t_Log); Assert.assertFalse(instance.handle(t_Parameters)); EasyMock.verify(t_Log); }
From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.ReportUnusedPropertiesHandler.java
/** * Reports any unused property./* w w w . j ava 2 s . c o m*/ * @param properties the declared properties. * @param columns the properties from the result set. * @param sql the query itself. * @param log the {@link Log}. */ protected void diagnoseUnusedProperties(@NotNull final List<Property<String>> properties, @NotNull final List<Property<String>> columns, @NotNull final Sql<String> sql, @Nullable final Log log) { if (log != null) { @NotNull final List<Property<String>> t_lExtraProperties = detectExtraProperties(properties, columns); int t_iIndex = 1; for (@Nullable final Property<String> t_ExtraProperty : t_lExtraProperties) { if (t_ExtraProperty != null) { log.warn("Column declared but not used (" + t_iIndex + ", " + t_ExtraProperty.getColumnName() + ", " + t_ExtraProperty.getType() + "), in sql " + sql.getId()); } t_iIndex++; } } }
From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.ReportUnusedPropertiesHandlerTest.java
/** * Checks whether it detects unused properties. * Throws QueryJBuildException//from www .j a v a2 s.c o m */ @Test public void detects_unused_properties() throws QueryJBuildException { @NotNull final Log t_Log = EasyMock.createNiceMock(Log.class); @NotNull final ReportUnusedPropertiesHandler instance = new ReportUnusedPropertiesHandler() { /** * {@inheritDoc} */ @Nullable @Override protected Log retrieveLog() { return t_Log; } }; @NotNull final QueryJCommand t_Parameters = new ConfigurationQueryJCommandImpl( new SerializablePropertiesConfiguration()); @NotNull final List<Property<String>> t_lProperties = new ArrayList<>(3); t_lProperties.add(new PropertyElement<>("name", "name", 1, String.class.getSimpleName(), false)); t_lProperties.add(new PropertyElement<>("tmst", "tmst", 2, "Date", false)); t_lProperties.add(new PropertyElement<>("flag", "flg", 3, int.class.getSimpleName(), false)); @NotNull final List<Property<String>> t_lColumns = new ArrayList<>(2); t_lColumns.add(new PropertyElement<>("name", "name", 1, String.class.getSimpleName(), false)); t_lColumns.add(new PropertyElement<>("tmst", "tmst", 2, "Date", false)); @NotNull final Sql<String> t_Sql = new SqlElement<>("id", "dao", "name", String.class.getSimpleName(), SqlCardinality.SINGLE, "all", true, false, "description"); new QueryJCommandWrapper<List<Property<String>>>(t_Parameters) .setSetting(RetrieveResultPropertiesHandler.CURRENT_PROPERTIES, t_lProperties); new QueryJCommandWrapper<List<Property<String>>>(t_Parameters) .setSetting(RetrieveResultSetColumnsHandler.CURRENT_COLUMNS, t_lColumns); new QueryJCommandWrapper<Sql<String>>(t_Parameters).setSetting(RetrieveQueryHandler.CURRENT_SQL, t_Sql); t_Log.warn(EasyMock.anyObject()); EasyMock.expectLastCall(); EasyMock.replay(t_Log); Assert.assertFalse(instance.handle(t_Parameters)); EasyMock.verify(t_Log); }
From source file:org.acmsl.queryj.metadata.AbstractSqlDecorator.java
/** * Retrieves the parameters./* w ww . j av a2 s . co m*/ * @param parameterRefs the parameter references. * @param sqlParameterDAO the {@link SqlParameterDAO} instance. * @param metadataTypeManager the metadata type manager. * @return such information. */ @NotNull protected List<Parameter<DecoratedString, ?>> getParameters(@NotNull final List<ParameterRef> parameterRefs, @NotNull final SqlParameterDAO sqlParameterDAO, final MetadataTypeManager metadataTypeManager) { @NotNull final List<Parameter<DecoratedString, ?>> result = new ArrayList<>(); for (@Nullable final ParameterRef t_ParameterRef : parameterRefs) { @Nullable final Parameter<String, ?> t_Parameter; if (t_ParameterRef != null) { t_Parameter = sqlParameterDAO.findByPrimaryKey(t_ParameterRef.getId()); if (t_Parameter != null) { result.add(new CachingParameterDecorator<>(t_Parameter, metadataTypeManager)); } else { try { final Log t_Log = UniqueLogFactory.getLog(SqlDecorator.class); if (t_Log != null) { t_Log.warn("Referenced parameter not found:" + t_ParameterRef.getId()); } } catch (@NotNull final Throwable throwable) { // class-loading problem. } } } } return result; }
From source file:org.acmsl.queryj.metadata.AbstractSqlDecorator.java
/** * Retrieves the result class./*from w ww . j av a 2 s . c o m*/ * @param dao the DAO name. * @param repository the repository. * @param cardinality the cardinality. * @param resultRef the result ref. * @param resultDAO the {@link SqlResultDAO} instance. * @return such information. */ @NotNull protected String getResultClass(@Nullable final DecoratedString dao, @Nullable final DecoratedString repository, @NotNull final SqlCardinality cardinality, @Nullable final ResultRef resultRef, @NotNull final SqlResultDAO resultDAO) { @NotNull final StringBuilder result = new StringBuilder(); final boolean multiple = cardinality.equals(SqlCardinality.MULTIPLE); if (multiple) { result.append(MULTIPLE_RESULT_CLASS); } if (resultRef == null) { if (multiple) { result.append('<'); } if (dao != null) { result.append(dao.getVoName()); } else if (repository != null) { result.append(repository.getVoName()); } if (multiple) { result.append('>'); } } else { @Nullable final Result<String> t_Result = resultDAO.findByPrimaryKey(resultRef.getId()); if (t_Result != null) { if (multiple) { result.append('<'); } result.append(t_Result.getClassValue()); if (multiple) { result.append('>'); } } else { try { final Log t_Log = UniqueLogFactory.getLog(Literals.CUSTOM_SQL); if (t_Log != null) { t_Log.warn(Literals.REFERENCED_RESULT_NOT_FOUND + resultRef.getId()); } } catch (@NotNull final Throwable throwable) { // class-loading problem. } } } return result.toString(); }
From source file:org.acmsl.queryj.metadata.AbstractSqlDecorator.java
/** * Retrieves the result./*from w w w. ja v a 2 s . co m*/ * @param resultRef the {@link ResultRef} instance. * @param sqlResultDAO the {@link SqlResultDAO} instance. * @return such information. */ @Nullable protected Result<DecoratedString> getResult(@Nullable final ResultRef resultRef, @NotNull final SqlResultDAO sqlResultDAO) { @Nullable Result<DecoratedString> result = null; if (resultRef != null) { @Nullable final Result<String> t_Result = sqlResultDAO.findByPrimaryKey(resultRef.getId()); if (t_Result != null) { result = decorate(t_Result); } else { try { final Log t_Log = UniqueLogFactory.getLog(Literals.CUSTOM_SQL); if (t_Log != null) { t_Log.warn(Literals.REFERENCED_RESULT_NOT_FOUND + resultRef.getId()); } } catch (@NotNull final Throwable throwable) { // class-loading problem. } } } return result; }
From source file:org.adeptnet.atlassian.common.AuthenticatorInterface.java
default public Principal getUserFromUserName(final HttpServletRequest request, final HttpServletResponse response, final String userName, final String method) { final Log log = getLog(); final Principal user = getUser(userName); if (user == null) { log.warn(String.format("User not found: %s", userName)); return null; }//from ww w . j av a 2 s . c o m log.info(String.format("Logged in %s via %s", user, method)); if (!authoriseUserAndEstablishSession(request, response, user)) { log.warn(String.format("User not authorised: %s", userName)); return null; } return user; }