Commit 25dcabce by Tuomas Riihimäki

Formatting and code style

No functional changes. Only formatting. Found with sonarcube
1 parent a1396449
......@@ -265,16 +265,16 @@ public class BillBean implements BillBeanLocal {
}
// if there is autoproducts, check that they exists in bill
for(Product product : productBean.listUserShoppableProducts()) {
if(product.isUsershopAutoproduct()) {
for (Product product : productBean.listUserShoppableProducts()) {
if (product.isUsershopAutoproduct()) {
boolean containsAutoproduct = false;
for(BillLine line : bill.getBillLines()) {
if(line.getLineProduct() != null && line.getLineProduct().equals(product) && line.getQuantity().compareTo(BigDecimal.ONE) >= 0) {
for (BillLine line : bill.getBillLines()) {
if (line.getLineProduct() != null && line.getLineProduct().equals(product) && line.getQuantity().compareTo(BigDecimal.ONE) >= 0) {
containsAutoproduct = true;
}
}
if(!containsAutoproduct) {
if (!containsAutoproduct) {
BillLine line = new BillLine(bill, product, BigDecimal.ONE);
bill.getBillLines().add(line);
......@@ -295,8 +295,9 @@ public class BillBean implements BillBeanLocal {
*/
private void createPlaceslots(Bill bill) {
for (BillLine bl : bill.getBillLines()) {
if (bl == null)
if (bl == null) {
return;
}
Product prod = bl.getLineProduct();
if (prod == null || prod.getPlaces() == null || prod.getPlaces().isEmpty()) {
// Not a place product.
......@@ -304,8 +305,7 @@ public class BillBean implements BillBeanLocal {
}
int count = bl.getQuantity().intValue();
Date now = new Date();
for (int i = 0; i < count; ++i)
{
for (int i = 0; i < count; ++i) {
PlaceSlot ps = new PlaceSlot();
ps.setBill(bill);
ps.setCreated(now);
......
......@@ -38,27 +38,8 @@ public class BootstrapBean implements BootstrapBeanLocal {
@EJB
UserFacade userFacade;
public BootstrapBean() {
}
/**
* Runs a "ALTER TABLE
* <table>
* <statement>" for each of tables.
*
* @param alterStatement
* e.g. "ADD meta json"
* @param tables
* table name strings
* @return1
*/
private static final String[] alterTables(String alterStatement, String... tables) {
String[] strings = new String[tables.length];
for (int i = 0; i < tables.length; i++) {
strings[i] = "ALTER TABLE \"" + tables[i] + "\" " + alterStatement;
}
return strings;
}
@EJB
private DBModelFacade dbModelFacade;
private static final List<String[]> dbUpdates = new ArrayList<String[]>();
static {
......@@ -260,10 +241,29 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE maps ADD COLUMN mime_type TEXT default 'image/png'",
});
} // start_time timestamp without time zone,
}
@EJB
private DBModelFacade dbModelFacade;
public BootstrapBean() {
}
/**
* Runs a "ALTER TABLE
* <table>
* <statement>" for each of tables.
*
* @param alterStatement
* e.g. "ADD meta json"
* @param tables
* table name strings
* @return1
*/
private static final String[] alterTables(String alterStatement, String... tables) {
String[] strings = new String[tables.length];
for (int i = 0; i < tables.length; i++) {
strings[i] = "ALTER TABLE \"" + tables[i] + "\" " + alterStatement;
}
return strings;
}
@PostConstruct
public void bootstrap() {
......@@ -272,7 +272,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
private void doDBUpdates() {
DBModel dBm = dbModelFacade.findLastRevision();
Integer upIdx = (dbUpdates.size() - 1);
Integer upIdx = dbUpdates.size() - 1;
if (dBm != null) {
Integer revId = dBm.getRevision();
......
......@@ -2,7 +2,6 @@ package fi.codecrew.moya.beans;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Stateless;
import fi.iudex.utils.irc.IrcBot;
......@@ -19,7 +18,6 @@ public class BotBean implements BotBeanLocal {
* Default constructor.
*/
public BotBean() {
// TODO Auto-generated constructor stub
}
@Override
......
......@@ -86,8 +86,6 @@ public class CardPrintBean implements CardPrintBeanLocal {
@EJB
private CardTemplateFacade cardTemplateFacade;
@EJB
private UserFacade userfacade;
@EJB
private BarcodeBean barcodeBean;
@EJB
private PrintedCardFacade printedCardFacade;
......@@ -99,7 +97,6 @@ public class CardPrintBean implements CardPrintBeanLocal {
* Default constructor.
*/
public CardPrintBean() {
// TODO Auto-generated constructor stub
}
// TODO: Roles?
......
......@@ -95,7 +95,6 @@ public class JaasBean implements MoyaRealmBeanRemote {
user = eventUser.getUser();
}
// no user found, let's see if user is stupid and using email-address instead of username
// this is how it work's in theory, on practice, the fucking UserPrincipal get it's principal
// from used loginname, so, let's do this shit on loginview
......@@ -141,7 +140,7 @@ public class JaasBean implements MoyaRealmBeanRemote {
}
// jos logitetaan anomuumi, niin uuden tapahtuman luominen hajoaa jännästi.
if(!user.isAnonymous())
if (!user.isAnonymous())
secubean.sendMessage(MoyaEventType.LOGIN_SUCCESSFULL, eventUser, "User logged in with username: '", username, "' eventuser: ", eventUser);
} else {
secubean.sendMessage(MoyaEventType.LOGIN_FAILED, eventUserFacade.findByLogin(User.ANONYMOUS_LOGINNAME), "Login failed: Username not found: ", username);
......@@ -225,8 +224,8 @@ public class JaasBean implements MoyaRealmBeanRemote {
default:
throw new RuntimeException("Unknown user type: " + usertype);
}
} catch (Throwable t) {
logger.warn("UserType authentication " + usertype);
} catch (Exception t) {
logger.warn("UserType authentication " + usertype, t);
}
}
......
......@@ -212,10 +212,10 @@ public class PermissionBean implements PermissionBeanLocal {
public String getPrincipal() {
Principal principal = context.getCallerPrincipal();
logger.debug("Principal: {}", principal);
//logger.debug("Principal: {}", principal);
String principalName = principal.getName();
logger.debug("Principal is {}", principalName);
// logger.debug("Principal is {}", principalName);
return principalName;
}
......
......@@ -23,6 +23,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
......@@ -51,18 +53,16 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal {
// TODO Auto-generated constructor stub
}
private final Map<String, String> sessionUsers = Collections.synchronizedMap(new HashMap<String, String>());
private final Set<HttpSession> sessions = Collections.synchronizedSet(new HashSet<HttpSession>());
private final ConcurrentSkipListMap<String, String> sessionUsers = new ConcurrentSkipListMap<String, String>();
private final ConcurrentSkipListSet<HttpSession> sessions = new ConcurrentSkipListSet<HttpSession>();
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(SessionMgmtBean.class);
@Override
public void updateSessionUser(String sessionId, String user)
{
public void updateSessionUser(String sessionId, String user) {
if (!sessionUsers.containsKey(sessionId))
{
if (!sessionUsers.containsKey(sessionId)) {
sessionUsers.put(sessionId, user);
}
}
......@@ -80,8 +80,7 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal {
@Override
@RolesAllowed(UserPermission.S_MANAGE_HTTP_SESSION)
public Set<HttpSession> getSessions()
{
public Set<HttpSession> getSessions() {
return Collections.unmodifiableSet(sessions);
}
......
......@@ -34,8 +34,7 @@ import fi.codecrew.moya.model.Menuitem;
@LocalBean
public class MenuitemFacade extends IntegerPkGenericFacade<Menuitem> {
private static final Logger logger = LoggerFactory
.getLogger(MenuitemFacade.class);
private static final Logger logger = LoggerFactory.getLogger(MenuitemFacade.class);
public MenuitemFacade() {
......@@ -60,7 +59,7 @@ public class MenuitemFacade extends IntegerPkGenericFacade<Menuitem> {
create(ret);
}
return ret;
} catch (Throwable e) {
} catch (Exception e) {
logger.warn("Exception menussa" + url, e);
}
return null;
......
......@@ -31,86 +31,83 @@ import javax.persistence.Table;
@Table(name = "poll_answer")
public class PollAnswer extends GenericEntity implements Serializable {
/**
/**
*
*/
private static final long serialVersionUID = -9170023819401407461L;
@Lob
@Column(name = "answer_text", nullable = true)
private String answerText = "";
@Column(name = "answer_boolean", nullable = true)
private Boolean answerBoolean = false;
@ManyToOne
@JoinColumn(name = "possible_answer_id", referencedColumnName = PossibleAnswer.ID_COLUMN, nullable = false)
private PossibleAnswer choice;
@ManyToOne
@JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
private EventUser user;
public PollAnswer() {
super();
}
@Override
public boolean equals(Object o)
{
boolean ret = false;
if (o instanceof PollAnswer)
{
PollAnswer objO = (PollAnswer) o;
if (super.getId() == null)
{
ret = choice.equals(objO.getChoice());
}
else
{
ret = super.equals(o);
}
}
return ret;
}
public PollAnswer(PossibleAnswer possible) {
super();
choice = possible;
}
public void setAnswerText(String answerText) {
this.answerText = answerText;
}
public String getAnswerText() {
return answerText;
}
public void setChoice(PossibleAnswer choice) {
this.choice = choice;
}
public PossibleAnswer getChoice() {
return choice;
}
public void setUser(EventUser user) {
this.user = user;
}
public EventUser getUser() {
return user;
}
public void setAnswerBoolean(Boolean answerBoolean) {
this.answerBoolean = answerBoolean;
}
public Boolean getAnswerBoolean() {
return answerBoolean;
}
private static final long serialVersionUID = -9170023819401407461L;
@Lob
@Column(name = "answer_text", nullable = true)
private String answerText = "";
@Column(name = "answer_boolean", nullable = true)
private Boolean answerBoolean = false;
@ManyToOne
@JoinColumn(name = "possible_answer_id", referencedColumnName = PossibleAnswer.ID_COLUMN, nullable = false)
private PossibleAnswer choice;
@ManyToOne
@JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
private EventUser user;
public PollAnswer() {
super();
}
@Override
public boolean equals(Object o)
{
boolean ret = false;
if (o instanceof PollAnswer) {
PollAnswer objO = (PollAnswer) o;
if (super.getId() == null) {
ret = choice.equals(objO.getChoice());
} else {
ret = super.equals(o);
}
}
return ret;
}
public PollAnswer(PossibleAnswer possible) {
super();
choice = possible;
}
public void setAnswerText(String answerText) {
this.answerText = answerText;
}
public String getAnswerText() {
return answerText;
}
public void setChoice(PossibleAnswer choice) {
this.choice = choice;
}
public PossibleAnswer getChoice() {
return choice;
}
public void setUser(EventUser user) {
this.user = user;
}
public EventUser getUser() {
return user;
}
public void setAnswerBoolean(Boolean answerBoolean) {
this.answerBoolean = answerBoolean;
}
public Boolean getAnswerBoolean() {
return answerBoolean;
}
}
......@@ -13,9 +13,9 @@ import org.slf4j.LoggerFactory;
public enum SystemProperty {
MOYA_IRC_SERVER,
MOYA_IRC_CHANNEL("#moya-debug"),
MOYA_IRC_CHANNEL("#moya-debug"),
MOYA_IRC_SERVERPASS(),
;
private final String defaultValue;
......@@ -54,7 +54,7 @@ public enum SystemProperty {
Integer intval = null;
try {
intval = Integer.parseInt(val);
} catch (Throwable t) {
} catch (Exception t) {
intval = null;
logger.warn("Unable to parse system property '{}' value '{}' as integer. Defaulting to {}", name(), val, defaultIntegerValue);
}
......
......@@ -106,12 +106,12 @@ public class HostnameFilter implements Filter {
Principal userPrincipal = request.getUserPrincipal();
if (userPrincipal != null) {
String userString = userPrincipal.getName();
MDC.put("user", userString);
MDC.put("user", userString);
MDC.put("authtype", authType != null ? authType.name() : "null");
} else {
MDC.put("user", "null");
MDC.put("authtype", "null");
}
}
}
/**
......@@ -152,13 +152,11 @@ public class HostnameFilter implements Filter {
try {
authtype = AuthType.ANON;
httpRequest.login(User.ANONYMOUS_LOGINNAME, null);
} catch (Throwable t) {
} catch (Exception t) {
logger.warn("Error logging in as anonymous... ignoring.. ", t);
}
}
}
else if (!httpRequest.getUserPrincipal().getName().equals(User.ANONYMOUS_LOGINNAME))
{
} else if (!httpRequest.getUserPrincipal().getName().equals(User.ANONYMOUS_LOGINNAME)) {
authtype = AuthType.USER;
sessionmgmt.updateSessionUser(httpRequest.getSession().getId(), httpRequest.getUserPrincipal().getName());
}
......@@ -168,7 +166,7 @@ public class HostnameFilter implements Filter {
try {
insertLoggingContext((HttpServletRequest) request, authtype);
chain.doFilter(request, response);
} catch (Throwable t) {
} catch (Exception t) {
if (AuthType.REST == authtype) {
logger.warn("Caught exception at rest:", t);
}
......@@ -191,7 +189,6 @@ public class HostnameFilter implements Filter {
// }
private boolean restAuth(HttpServletRequest httpRequest, ServletResponse response) {
// logger.info("Trying to authenticate for REST query. url {}, params '{}' method: {}, content type {}, and length {}", httpRequest.getRequestURL(), httpRequest.getQueryString(), httpRequest.getMethod(), httpRequest.getContentType(), httpRequest.getContentLength());
StringBuilder hashBuilder = new StringBuilder();
hashBuilder.append("rest:");
......@@ -207,14 +204,11 @@ public class HostnameFilter implements Filter {
} catch (ServletException loginEx) {
ret = false;
logger.info("Rest api authentication failed! ", loginEx);
if (response instanceof HttpServletResponse)
{
if (response instanceof HttpServletResponse) {
HttpServletResponse httpResp = ((HttpServletResponse) response);
httpResp.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
} finally {
}
return ret;
}
......
......@@ -103,8 +103,7 @@ public class IrcServlet extends HttpServlet {
String ircserver = SystemProperty.MOYA_IRC_SERVER.getValueOrDefault();
logger.info("Got irc server system property {}", ircserver);
if (ircserver != null)
{
if (ircserver != null) {
logger.info("Starting IRC client with server {}", ircserver);
IrcBot bot = new IrcBot(ircserver, 6667, SystemProperty.MOYA_IRC_SERVERPASS.getValueOrNull(), SystemProperty.MOYA_IRC_CHANNEL.getValueOrDefault(), new Profile("moyabot", "Moya bot", "moya-bot"));
botbean.add(bot);
......@@ -132,7 +131,7 @@ public class IrcServlet extends HttpServlet {
try {
b.stop();
} catch (Throwable t) {
} catch (Exception t) {
logger.info("Error stopping bot", t);
}
}
......
......@@ -56,9 +56,6 @@ public class AuthView extends GenericCDIView {
private NavigationHandler navihandler;
@EJB
private transient BootstrapBeanLocal bootStrapBean;
@EJB
private PermissionBeanLocal permbean;
@EJB
......@@ -106,7 +103,7 @@ public class AuthView extends GenericCDIView {
return "/frontpage";
}
public void executeLogoutNoRedirect() {
HttpServletRequest req = getRequest();
if (permbean.isLoggedIn()) {
......@@ -119,8 +116,6 @@ public class AuthView extends GenericCDIView {
req.getSession().invalidate();
}
public void executeLogin() {
......@@ -128,21 +123,21 @@ public class AuthView extends GenericCDIView {
}
public void executeLogin(String onError) {
if (onError == null)
if (onError == null) {
onError = "/auth/loginError";
}
doLogin(onError);
}
private void doLogin(String onError) {
// bootStrapBean.saneDefaults();
// bootStrapBean.saneDefaults();
if (login == null || password == null || login.isEmpty() || password.isEmpty()) {
return;
}
HttpServletRequest request = getRequest();
if (request.getUserPrincipal() != null) {
logger.info("Principal not empty. need to logout first");
......@@ -156,12 +151,12 @@ public class AuthView extends GenericCDIView {
// first, let's make some blindshooting, email-login
String userlogin = userbean.findUsernameByEmailUsername(login.trim());
if(userlogin != null)
if (userlogin != null) {
login = userlogin;
}
try {
request.login(login.trim().toLowerCase(), password);
} catch (Throwable e) {
} catch (Exception e) {
logger.info("Error while trying to login {}", e.getMessage());
} finally {
......@@ -215,7 +210,6 @@ public class AuthView extends GenericCDIView {
}
public void executeAdduserAutoLogin(EventUser user, String password2) {
// TODO Auto-generated method stub
this.login = user.getLogin();
this.password = password2;
navihandler.saveNavigation("/admin/adduser/update");
......
......@@ -39,7 +39,7 @@ public class LocaleConverter implements Converter {
if (value != null && !value.isEmpty() && !"null".equals(value)) {
try {
ret = Locale.forLanguageTag(value);
} catch (Throwable t) {
} catch (Exception t) {
logger.warn("Error parsing locale: '{}'", value);
}
}
......@@ -57,10 +57,4 @@ public class LocaleConverter implements Converter {
return ret;
}
public static void main(String[] ad)
{
Locale loc = new Locale("fi", "FI");
System.out.println(loc.toLanguageTag());
System.out.println(loc.toString());
}
}
......@@ -58,7 +58,7 @@ public class HttpSessionWrapper implements HttpSession
Date ret = null;
try {
ret = new Date(session.getCreationTime());
} catch (Throwable t) {
} catch (Exception t) {
ret = null;
}
return ret;
......@@ -78,7 +78,7 @@ public class HttpSessionWrapper implements HttpSession
Date ret = null;
try {
ret = new Date(session.getLastAccessedTime());
} catch (Throwable t) {
} catch (Exception t) {
ret = null;
}
return ret;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!