Example usage for org.apache.commons.logging Log error

List of usage examples for org.apache.commons.logging Log error

Introduction

In this page you can find the example usage for org.apache.commons.logging Log error.

Prototype

void error(Object message, Throwable t);

Source Link

Document

Logs an error with error log level.

Usage

From source file:ome.logic.AdminImpl.java

@RolesAllowed("system")
@Transactional(readOnly = false)/*from   w w  w  .  ja  v a 2  s. c  om*/
public void synchronizeLoginCache() {

    final Log log = getBeanHelper().getLogger();
    final List<Map<String, Object>> dnIds = ldapUtil.lookupLdapAuthExperimenters();

    if (dnIds.size() > 0) {
        log.info("Synchronizing " + dnIds.size() + " ldap user(s)");
    }

    for (Map<String, Object> dnId : dnIds) {
        String dn = (String) dnId.get("dn");
        Long id = (Long) dnId.get("experimenter_id");
        try {
            Experimenter e = userProxy(id);
            ldapUtil.synchronizeLdapUser(e.getOmeName());
        } catch (ApiUsageException aue) {
            // User likely doesn't exist
            log.debug("User not found: " + dn);
        } catch (Exception e) {
            log.error("synchronizeLdapUser:" + dnId, e);
        }
    }
    context.publishEvent(new UserGroupUpdateEvent(this));
}

From source file:org.acmsl.queryj.AbstractQueryJChain.java

/**
 * Sends given command to a concrete chain.
 * @param chain the concrete chain./*from   w  w w.  j a v a  2 s . c  o m*/
 * @param command the command that represents which actions should be done.
 * @return <code>true</code> if the command is processed by the chain.
 * @throws QueryJBuildException if the process fails.
 */
protected boolean process(@NotNull final Chain<C, QueryJBuildException, CH> chain, @NotNull final C command)
        throws QueryJBuildException {
    boolean result = false;

    @Nullable
    final Log t_Log = command.getLog();

    final boolean t_bLoggingEnabled = (t_Log != null);

    boolean restart = false;

    do {
        try {
            @Nullable
            CH t_CurrentCommandHandler = null;

            do {
                t_CurrentCommandHandler = getNextChainLink(chain, t_CurrentCommandHandler);

                if (t_bLoggingEnabled) {
                    t_Log.debug("Next handler: " + t_CurrentCommandHandler);
                }

                if (t_CurrentCommandHandler != null) {
                    result = t_CurrentCommandHandler.handle(command);

                    if (t_bLoggingEnabled) {
                        t_Log.debug(t_CurrentCommandHandler + "#handle(QueryJCommand) returned " + result);
                    }
                }
            } while ((!result) && (t_CurrentCommandHandler != null) && (!restart));
        } catch (@NotNull final DevelopmentModeException devMode) {
            restart = true;
        } catch (@NotNull final QueryJBuildException buildException) {
            cleanUpOnError(buildException, command);

            if (t_bLoggingEnabled) {
                t_Log.error("QueryJ could not generate sources correctly.", buildException);
            }

            throw buildException;
        }
    } while (restart);

    return result;
}

From source file:org.acmsl.queryj.api.AbstractTemplateGenerator.java

/**
 * Performs the generation process./*from  w  w w.j  a  va  2s . c om*/
 * @param template the template.
 * @param caching whether template caching is enabled.
 * @param fileName the file name.
 * @param outputDir the output folder.
 * @param rootFolder the root folder.
 * @param charset the {@link Charset} to use.
 * @param fileUtils the {@link FileUtils} instance.
 * @param log the {@link Log} instance.
 * @return whether it gets written to disk.
 * @throws IOException if the template cannot be written to disk.
 * @throws QueryJBuildException if the template cannot be generated.
 */
protected boolean generate(@NotNull final N template, final boolean caching, @NotNull final String fileName,
        @NotNull final File outputDir, @NotNull final File rootFolder, @NotNull final Charset charset,
        @NotNull final FileUtils fileUtils, @Nullable final Log log) throws IOException, QueryJBuildException {
    boolean result = false;

    @Nullable
    final ST relevantStTemplate = template.generate(true);

    @Nullable
    final String relevantContent;

    if (relevantStTemplate != null) {
        relevantContent = relevantStTemplate.render();
    } else {
        relevantContent = null;
    }

    if (relevantContent != null) {
        @NotNull
        final String newHash = computeHash(relevantContent, charset);

        @Nullable
        final String oldHash = retrieveHash(fileName, outputDir, rootFolder, charset, fileUtils);

        if ((oldHash == null) || (!newHash.equals(oldHash))) {
            result = true;
        }

        if (result) {
            @NotNull
            final String t_strOutputFile = outputDir.getAbsolutePath() + File.separator + fileName;

            if (caching) {
                serializeTemplate(template, getOutputDir(outputDir, rootFolder).getAbsolutePath()
                        + File.separator + "." + fileName + ".ser");
            }

            @Nullable
            final ST stTemplate = template.generate(false);

            @Nullable
            String t_strFileContents = "";

            if (stTemplate != null) {
                try {
                    t_strFileContents = stTemplate.render();
                } catch (@NotNull final Throwable throwable) {
                    @Nullable
                    final Log t_Log = UniqueLogFactory.getLog(AbstractQueryJTemplate.class);

                    if (t_Log != null) {
                        t_Log.error("Error in template " + template.getTemplateName(), throwable);
                    }
                    /*                    @Nullable final STTreeView debugTool =
                        new StringTemplateTreeView("Debugging " + getTemplateName(), t_Template);
                            
                    debugTool.setVisible(true);
                            
                    while (debugTool.isVisible())
                    {
                        try
                        {
                            Thread.sleep(1000);
                        }
                        catch (InterruptedException e)
                        {
                            e.printStackTrace();
                        }
                    }*/
                }
            }

            if (!"".equals(t_strFileContents)) {
                @NotNull
                final File t_FinalDir = new File(t_strOutputFile).getParentFile();

                final boolean folderCreated = t_FinalDir.mkdirs();

                if ((!folderCreated) && (!outputDir.exists())) {
                    throw new IOException("Cannot create output dir: " + t_FinalDir);
                } else if (t_strFileContents != null) {
                    if ((log != null) && (log.isDebugEnabled())) {
                        log.debug("Writing " + (t_strFileContents.length() * 2) + " bytes (" + charset + "): "
                                + t_strOutputFile);
                    }
                }

                if (t_strFileContents != null) {
                    fileUtils.writeFile(t_strOutputFile, t_strFileContents, charset);
                }

                writeHash(newHash, fileName, outputDir, rootFolder, charset, fileUtils);
            } else {
                if ((log != null) && (log.isDebugEnabled())) {
                    log.debug("Not writing " + t_strOutputFile + " since the generated content is empty");
                }
            }
        }
    }

    return result;
}

From source file:org.acmsl.queryj.api.handlers.BasePerTableTemplateBuildHandler.java

/**
 * Builds the template./*from w  w w . j  av  a 2 s  . c  o  m*/
 * @param parameters the parameters.
 * @param metadataManager the database metadata manager.
 * @param templateFactory the template factory.
 * @param tables the tables.
 * @throws QueryJBuildException if the template cannot be built.
 */
@SuppressWarnings("unchecked")
protected void buildTemplate(@NotNull final QueryJCommand parameters,
        @NotNull final MetadataManager metadataManager, @NotNull final TF templateFactory,
        @NotNull final List<Table<String, Attribute<String>, List<Attribute<String>>>> tables)
        throws QueryJBuildException {
    @NotNull
    final List<T> t_lTemplates = new ArrayList<>();

    @Nullable
    T t_Template;

    for (@Nullable
    final Table<String, Attribute<String>, List<Attribute<String>>> t_Table : tables) {
        if (t_Table != null) {
            if (metadataManager.isGenerationAllowedForTable(t_Table.getName())) {
                List<Row<String>> t_lStaticContent = retrieveCachedStaticContent(parameters, t_Table.getName());

                if (t_lStaticContent == null) {
                    try {
                        t_lStaticContent = retrieveStaticContent(t_Table.getName(),
                                metadataManager.getTableDAO());
                    } catch (@Nullable final SQLException cannotRetrieveTableContents) {
                        @Nullable
                        final Log t_Log = UniqueLogFactory.getLog(BasePerTableTemplateBuildHandler.class);

                        if (t_Log != null) {
                            t_Log.error("Cannot retrieve static contents for " + t_Table.getName(),
                                    cannotRetrieveTableContents);
                        }
                    }
                    if (t_lStaticContent == null) {
                        t_lStaticContent = new ArrayList<>(0);
                    }
                    storeCachedStaticContent(t_lStaticContent, parameters, t_Table.getName());
                }

                t_Template = createTemplate(templateFactory,
                        /*
                        retrievePackage(
                            t_Table.getName(), metadataManager.getEngine(), parameters),
                        */
                        t_Table.getName(), t_lStaticContent, parameters);

                if (t_Template != null) {
                    t_lTemplates.add(t_Template);
                }
            }
        }
    }

    storeTemplates(t_lTemplates, parameters);
}

From source file:org.acmsl.queryj.api.handlers.BasePerTableTemplateBuildHandler.java

/**
 * Checks whether given table contains static values or not.
 * @param parameters the parameter map./*from   ww w. j a v  a  2  s  .  c om*/
 * @param tableName the table name.
 * @param metadataManager the {@link MetadataManager} instance.
 * @param decoratorFactory the decorator factory.
 * @return such information.
 */
@SuppressWarnings("unused")
@Nullable
protected List<Row<String>> retrieveStaticContent(@NotNull final QueryJCommand parameters,
        @NotNull final String tableName, @NotNull final MetadataManager metadataManager,
        @NotNull final DecoratorFactory decoratorFactory) {
    @Nullable
    List<Row<String>> result = retrieveCachedStaticContent(parameters, tableName);

    if (result == null) {
        try {
            result = retrieveStaticContent(tableName, metadataManager.getTableDAO());

            if (result == null) {
                result = new ArrayList<>(0);
            }
            storeCachedStaticContent(result, parameters, tableName);
        } catch (@NotNull final SQLException sqlException) {
            @Nullable
            final Log t_Log = UniqueLogFactory.getLog(BasePerTableTemplateBuildHandler.class);

            if (t_Log != null) {
                t_Log.error("Error retrieving static content for " + tableName, sqlException);
            }
        }
    }

    return result;
}

From source file:org.acmsl.queryj.api.MetaLanguageUtils.java

/**
* Retrieves the attribute used to identify table content.
* @param tableComment the table's comment.
* @return such attribute.// w w w. j a v a 2s.c  om
*/
@Nullable
public String retrieveStaticAttribute(@Nullable final String tableComment) {
    @Nullable
    String result = null;

    if (!isEmpty(tableComment)) {
        try {
            assert tableComment != null;

            @NotNull
            final PerCommentParser t_Parser = setUpParser(tableComment);

            @NotNull
            final ParseTree tree = t_Parser.tableComment();

            @NotNull
            final PerCommentVisitor<String> visitor = new PerCommentTabStaticVisitor();

            result = visitor.visit(tree);
        } catch (@NotNull final RecognitionException recognitionException) {
            @Nullable
            final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class);

            if (t_Log != null) {
                t_Log.error(Literals.INVALID_TABLE_COMMENT + tableComment, recognitionException);
            }
        }
    }

    return result;
}

From source file:org.acmsl.queryj.api.MetaLanguageUtils.java

/**
 * Retrieves the parent table in an ISA relationship, as
 * declared by the table comment./*  www .ja  v  a2 s  . c o m*/
 * @param tableComment the table's comment.
 * @return the parent table, or <code>null</code> otherwise.
 */
@Nullable
public String retrieveDeclaredParent(@NotNull final String tableComment) {
    @Nullable
    String result = null;

    if (!isEmpty(tableComment)) {
        try {
            @NotNull
            final PerCommentParser t_Parser = setUpParser(tableComment);

            @NotNull
            final ParseTree tree = t_Parser.tableComment();

            @NotNull
            final PerCommentVisitor<String> visitor = new PerCommentTabIsaVisitor();

            result = visitor.visit(tree);
        } catch (@NotNull final RecognitionException recognitionException) {
            @Nullable
            final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class);

            if (t_Log != null) {
                t_Log.error(Literals.INVALID_TABLE_COMMENT + tableComment, recognitionException);
            }
        }
    }

    return result;
}

From source file:org.acmsl.queryj.api.MetaLanguageUtils.java

/**
 * Retrieves the table the comment owner discriminates among its
 * children in an ISA relationship.// w  ww  .ja  v  a  2s  .c  om
 * @param tableComment the table's comment.
 * @return the ISA parent table.
 */
@SuppressWarnings("unused")
@Nullable
public String retrieveDiscriminatingParent(@NotNull final String tableComment) {
    @Nullable
    String result = null;

    if (!isEmpty(tableComment)) {
        try {
            @NotNull
            final PerCommentParser t_Parser = setUpParser(tableComment);

            @NotNull
            final ParseTree tree = t_Parser.tableComment();

            @NotNull
            final PerCommentVisitor<String> visitor = new PerCommentTabIsatypeVisitor();

            result = visitor.visit(tree);
        } catch (@NotNull final RecognitionException recognitionException) {
            @Nullable
            final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class);

            if (t_Log != null) {
                t_Log.error(Literals.INVALID_TABLE_COMMENT + tableComment, recognitionException);
            }
        }
    }

    return result;
}

From source file:org.acmsl.queryj.api.MetaLanguageUtils.java

/**
 * Retrieves the value to denote <code>true</code> values. If
 * <code>null</code>, then the column is not considered boolean.
 * @param columnComment the column comment.
 * @return the values to use in the database to denote <code>true</code>,
 * <code>false</code> and <code>null</code> values, or <code>null</code>
 * if the column is not boolean./*from w w w  .jav a  2s  . c  o m*/
 */
@NotNull
@SuppressWarnings("unused")
public String[] retrieveColumnBool(@NotNull final String columnComment) {
    @Nullable
    String[] result = null;

    boolean done = false;

    if (!isEmpty(columnComment)) {
        try {
            @NotNull
            final PerCommentParser t_Parser = setUpParser(columnComment);

            @NotNull
            final ParseTree tree = t_Parser.columnComment();

            @NotNull
            final PerCommentVisitor<List<String>> visitor = new PerCommentColBoolVisitor();

            @Nullable
            final List<String> boolDefs = visitor.visit(tree);

            if ((boolDefs != null) && (boolDefs.size() > 1)) {
                done = true;
                result = boolDefs.toArray(new String[boolDefs.size()]);
            }
        } catch (@NotNull final RecognitionException recognitionException) {
            @Nullable
            final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class);

            if (t_Log != null) {
                t_Log.error(Literals.INVALID_COLUMN_COMMENT + columnComment, recognitionException);
            }
        }
    }

    if ((!done) || (result == null)) {
        result = new String[0];
    }

    return result;
}

From source file:org.acmsl.queryj.api.MetaLanguageUtils.java

/**
 * Retrieves whether the column is meant to be read-only from the
 * Java side (i.e. a last-modified or creation-date timestamp).
 * @param columnComment the column comment.
 * @return such condition.//from  w ww.  j  a  va 2  s.com
 */
@SuppressWarnings("unused")
public boolean retrieveColumnReadOnly(@NotNull final String columnComment) {
    boolean result = false;

    if (!isEmpty(columnComment)) {
        try {
            @NotNull
            final PerCommentParser t_Parser = setUpParser(columnComment);

            @NotNull
            final ParseTree tree = t_Parser.columnComment();

            @NotNull
            final PerCommentVisitor<Boolean> visitor = new PerCommentColReadonlyVisitor();

            @Nullable
            final Boolean resultValue = visitor.visit(tree);

            if (resultValue != null) {
                result = resultValue;
            }
        } catch (@NotNull final RecognitionException recognitionException) {
            @Nullable
            final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class);

            if (t_Log != null) {
                t_Log.error(Literals.INVALID_COLUMN_COMMENT + columnComment, recognitionException);
            }
        }
    }

    return result;
}