Skip to content
Merged

Dev #88

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public static Be5Exception accessDenied()
return Be5ErrorCode.ACCESS_DENIED.exception();
}

public static Be5Exception accessDenied(String info)
{
return Be5ErrorCode.ACCESS_DENIED.exception(info);
}

public static Be5Exception accessDeniedToOperation(String entityName, String operationName)
{
return Be5ErrorCode.ACCESS_DENIED_TO_OPERATION.exception(entityName, operationName);
Expand Down Expand Up @@ -164,7 +169,7 @@ public static String getMessage(Throwable err)
return HtmlUtils.escapeHTML(out.toString());
}

private static String getFullStackTraceLine(StackTraceElement e)
public static String getFullStackTraceLine(StackTraceElement e)
{
return e.getClassName() + "." + e.getMethodName()
+ "(" + e.getFileName() + ":" + e.getLineNumber() + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ErrorTitles
TITLES.put(UNKNOWN_OPERATION, "Operation not found: $1.$2");
TITLES.put(NOT_FOUND, "Element not found: $1");

TITLES.put(ACCESS_DENIED, "Access denied");
TITLES.put(ACCESS_DENIED, "Access denied. $1");
TITLES.put(ACCESS_DENIED_TO_QUERY, "Access denied to query: $1.$2");
TITLES.put(ACCESS_DENIED_TO_OPERATION, "Access denied to operation: $1.$2");
TITLES.put(OPERATION_NOT_ASSIGNED_TO_QUERY, "Operation '$1.$3' not assigned to query: '$2'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,69 +103,6 @@ public static void registerMetaClass(Class<? extends MetaClass> metaClazz, Class
}
}

// public String getErrorCodeLine(Throwable e)
// {
// Set<String> printedGroovyClasses = new HashSet<>();
// Throwable err = e;
//
// Stack<Throwable> throwables = new Stack<>();
// throwables.add(err);
// while (err.getCause() != null)
// {
// throwables.add(err.getCause());
// err = err.getCause();
// }
//
// StringBuilder sb = new StringBuilder();
// while (!throwables.empty())
// {
// err = throwables.pop();
//
// StackTraceElement[] stackTrace = err.getStackTrace();
// for (int i = 0; i < stackTrace.length; i++)
// {
// if(stackTrace[i].getFileName() != null && stackTrace[i].getFileName().endsWith(".groovy")
// && !printedGroovyClasses.contains(stackTrace[i].getFileName()))
// {
// printedGroovyClasses.add(stackTrace[i].getFileName());
// sb.append(getErrorCodeLinesForClass(stackTrace[i]));
// break;
// }
// }
// }
//
// return sb.toString();
// }
//
// private String getErrorCodeLinesForClass(StackTraceElement e)
// {
// int lineID = e.getLineNumber();
// StringBuilder sb = new StringBuilder("\n" + Be5Exception.getFullStackTraceLine(e));
//
// String className = e.getClassName().indexOf('$') == -1
// ? e.getClassName()
// : e.getClassName().substring(0, e.getClassName().indexOf('$'));
//
// String code = groovyOperationLoaderProvider.get()
// .getByFullName(className + ".groovy")
// .getCode();
// String lines[] = HtmlUtils.escapeHTML(code).split("\\r?\\n");
//
// sb.append("\n\n<code>");
// for (int i = Math.max(0, lineID - 4); i < Math.min(lineID + 3, lines.length); i++)
// {
// String lineNumber = String.format("%4d", i+1)+" | ";
// if(lineID == i+1){
// sb.append("<span style=\"color: #e00000;\">").append(lineNumber).append(lines[i]).append("</span>\n");
// }else{
// sb.append(lineNumber).append(lines[i]).append("\n");
// }
// }
// sb.append("</code>");
//
// return sb.toString();
// }

//
// @SuppressWarnings( "unchecked" )
// public static List<String> toCompilationMessages(List errors0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.developmentontheedge.be5.metadata.sql.DatabaseUtils;
import com.developmentontheedge.be5.metadata.sql.Rdbms;
import com.developmentontheedge.be5.metadata.util.JULLogger;
import com.developmentontheedge.sql.format.Dbms;
import com.developmentontheedge.sql.format.dbms.Dbms;
import org.apache.commons.dbcp.BasicDataSource;

import javax.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ public Locale getLocale(Locale locale)

if(locale == null || !languages.contains(locale.getLanguage()))
{
return new Locale( languages.get(0) );
if(languages.size() > 0)
return new Locale( languages.get(0) );
else
return Locale.US;
}
else
{
Expand Down Expand Up @@ -418,11 +421,19 @@ public Map<String, ColumnDef> getColumns(Entity entity)
{
BeModelElement scheme = entity.getAvailableElement("Scheme");
if(scheme == null) return new HashMap<>();
BeCaseInsensitiveCollection<ColumnDef> columns = (BeCaseInsensitiveCollection<ColumnDef>) ((TableDef) scheme).get("Columns");

return StreamSupport.stream(columns.spliterator(), false).collect(
Utils.toLinkedMap(ColumnDef::getName, Function.identity())
);
if(scheme instanceof TableDef)
{
BeCaseInsensitiveCollection<ColumnDef> columns = (BeCaseInsensitiveCollection<ColumnDef>) ((TableDef) scheme).get("Columns");

return StreamSupport.stream(columns.spliterator(), false).collect(
Utils.toLinkedMap(ColumnDef::getName, Function.identity())
);
}
else
{
return Collections.emptyMap();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -719,4 +720,33 @@ public static <T> T ifNull( Object val, T def )
LinkedHashMap::new);
}

/**
* Generates random password, containing 8 symbols using english alphabet and numbers.
*
* @param userName user name
* @return generated password
*/
public static String newRandomPassword( String userName )
{
return newRandomPassword( userName, "abcdefghijklmnopqrstuvwxyz0123456789" );
}

/**
* Generates random password, containing 8 symbols from specified symbols array.
*
* @param userName user name
* @param pool symbols to use in password
* @return generated password
*/
public static String newRandomPassword( String userName, String pool )
{
StringBuffer pass = new StringBuffer();
Random random = userName == null ? new Random() : new Random( System.currentTimeMillis() + userName.hashCode() );
for( int i = 0; i < 8; i++ )
{
pass.append( pool.charAt( random.nextInt( pool.length() ) ) );
}
return pass.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.developmentontheedge.be5.base.BaseTest;
import com.developmentontheedge.be5.database.DataSourceService;
import com.developmentontheedge.sql.format.Dbms;
import com.developmentontheedge.sql.format.dbms.Dbms;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.developmentontheedge.be5.database;

import com.developmentontheedge.sql.format.Dbms;
import com.developmentontheedge.sql.format.dbms.Dbms;

import javax.sql.DataSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.developmentontheedge.be5.database.sql.ResultSetParser;
import com.developmentontheedge.be5.database.sql.SqlExecutor;
import com.developmentontheedge.be5.database.sql.SqlExecutorVoid;
import com.developmentontheedge.sql.format.Context;
import com.developmentontheedge.sql.format.Formatter;
import com.developmentontheedge.sql.format.dbms.Context;
import com.developmentontheedge.sql.format.dbms.Formatter;
import com.developmentontheedge.sql.model.DefaultParserContext;
import com.developmentontheedge.sql.model.SqlQuery;
import org.apache.commons.dbutils.QueryRunner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.developmentontheedge.be5.database.impl;

import com.developmentontheedge.be5.database.DataSourceService;
import com.developmentontheedge.sql.format.Dbms;
import com.developmentontheedge.sql.format.dbms.Dbms;

import javax.sql.DataSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface DbmsConnector

Connection getConnection() throws SQLException;

void releaseConnection( Connection conn );
//void releaseConnection( Connection conn );

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,33 @@ public Connection getConnection() throws SQLException
return connection;
}

private void returnConnection(Connection conn)
{
try
{
if(!conn.isClosed())
{
if(!conn.getAutoCommit())
conn.setAutoCommit(true);
conn.close();
}
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}

@Override
public void releaseConnection( Connection conn )
{
if ( null == conn )
{
return;
}

returnConnection(conn);
}
// private void returnConnection(Connection conn)
// {
// try
// {
// if(!conn.isClosed())
// {
// if(!conn.getAutoCommit())
// conn.setAutoCommit(true);
// conn.close();
// }
// }
// catch (SQLException e)
// {
// throw new RuntimeException(e);
// }
// }
//
// @Override
// public void releaseConnection( Connection conn )
// {
// if ( null == conn )
// {
// return;
// }
//
// returnConnection(conn);
// }

private RuntimeException propagate(SQLException e) {
log.log(Level.SEVERE, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,6 @@ else if( arg instanceof byte[] )
}
return null;
}
finally
{
connector.releaseConnection( conn );
}
}
catch( Exception e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void execute()
.setConnectionPassword(connectionPassword)
.setLogPath(logPath)
.setLogger(logger)
.setDebug(debug)
.setScript(script)
.setIgnoreMissing(ignoreMissing)
.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void execute()
.setConnectionPassword(connectionPassword)
.setLogPath(logPath)
.setLogger(logger)
.setDebug(debug)
.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void execute()
.setConnectionPassword(connectionPassword)
.setLogPath(logPath)
.setLogger(logger)
.setDebug(debug)
.setForceUpdate(forceUpdate)
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void execute() throws MojoFailureException
.setConnectionPassword(connectionPassword)
.setLogPath(logPath)
.setLogger(logger)
.setDebug(debug)
.setInputStream(inputStream)
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,30 @@
public class AppValidateMojo extends Be5Mojo
{
@Parameter (property = "BE5_RDBMS")
String rdbmsName;
private String rdbmsName;

@Parameter (property = "BE5_SKIP_VALIDATION")
boolean skipValidation = false;
private boolean skipValidation = false;

@Parameter (property = "BE5_CHECK_QUERY")
String queryPath;
private String queryPath;

@Parameter (property = "BE5_CHECK_ROLES")
boolean checkRoles;
private boolean checkRoles;

@Parameter (property = "BE5_CHECK_DDL")
String ddlPath;
private String ddlPath;

@Parameter (property = "BE5_SAVE_PROJECT")
boolean saveProject;
private boolean saveProject;

@Override
public void execute()
{
new AppValidate()
.setLogPath(logPath)
.setLogger(logger)
.setDebug(debug)
.setBe5ProjectPath(projectPath.toPath())
.setCheckQueryPath(queryPath)
.setDdlPath(ddlPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public abstract class Be5Mojo extends AbstractMojo
public File projectPath;

@Parameter (property = "BE5_UNLOCK_PROTECTED_PROFILE")
boolean unlockProtectedProfile = false;
protected boolean unlockProtectedProfile = false;

@Parameter (property = "BE5_DEBUG")
boolean debug = false;
protected boolean debug = false;

@Parameter (property = "BE5_LOG_PATH")
File logPath = Paths.get("target/sql").toFile();
protected File logPath = Paths.get("target/sql").toFile();

@Parameter (property = "BE5_PROFILE")
public String connectionProfileName;
Expand Down
Loading