Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Update code based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jul 30, 2013
1 parent f4a69be commit 3641a82
Show file tree
Hide file tree
Showing 70 changed files with 145 additions and 142 deletions.
Expand Up @@ -100,7 +100,7 @@ public void setLastChanged(Date lastChanged)

@SuppressWarnings("unused")
@PrePersist
protected void onPersist()
private void onPersist()
{
creationDate = new Date();
lastChanged = creationDate;
Expand Down
107 changes: 64 additions & 43 deletions zanata-war/src/main/java/org/zanata/ApplicationConfiguration.java
Expand Up @@ -31,6 +31,7 @@

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jboss.seam.Component;
Expand All @@ -49,6 +50,7 @@
import org.zanata.log4j.ZanataHTMLLayout;
import org.zanata.log4j.ZanataSMTPAppender;
import org.zanata.security.AuthenticationType;

import com.google.common.base.Objects;

@Name("applicationConfiguration")
Expand Down Expand Up @@ -77,16 +79,19 @@ public class ApplicationConfiguration implements Serializable
private Map<AuthenticationType, String> loginModuleNames = new HashMap<AuthenticationType, String>();
private Set<String> adminUsers = new HashSet<String>();

private String webAssetsUrl;
private String webAssetsStyleUrl;

// set by component.xml
private String webAssetsVersion = "";

@Observer( { EVENT_CONFIGURATION_CHANGED })
@Observer({ EVENT_CONFIGURATION_CHANGED })
@Create
public void load()
{
log.info("Reloading configuration");
databaseBackedConfig = (DatabaseBackedConfig)Component.getInstance(DatabaseBackedConfig.class);
jndiBackedConfig = (JndiBackedConfig)Component.getInstance(JndiBackedConfig.class);
databaseBackedConfig = (DatabaseBackedConfig) Component.getInstance(DatabaseBackedConfig.class);
jndiBackedConfig = (JndiBackedConfig) Component.getInstance(JndiBackedConfig.class);

this.loadLoginModuleNames();
this.validateConfiguration();
Expand All @@ -98,10 +103,10 @@ public void load()
*/
private void loadLoginModuleNames()
{
for( String policyName : jndiBackedConfig.getEnabledAuthenticationPolicies() )
for (String policyName : jndiBackedConfig.getEnabledAuthenticationPolicies())
{
AuthenticationType authType = AuthenticationType.valueOf( policyName.toUpperCase() );
loginModuleNames.put(authType, jndiBackedConfig.getAuthPolicyName( policyName ));
AuthenticationType authType = AuthenticationType.valueOf(policyName.toUpperCase());
loginModuleNames.put(authType, jndiBackedConfig.getAuthPolicyName(policyName));
}
}

Expand All @@ -111,19 +116,20 @@ private void loadLoginModuleNames()
private void validateConfiguration()
{
// Validate that only internal / openid authentication is enabled at once
if( loginModuleNames.size() > 2 )
if (loginModuleNames.size() > 2)
{
throw new RuntimeException("Multiple invalid authentication types present in Zanata configuration.");
}
else if( loginModuleNames.size() == 2 )
else if (loginModuleNames.size() == 2)
{
// Internal and Open id are the only allowed combined authentication types
if( !(loginModuleNames.containsKey(AuthenticationType.OPENID) && loginModuleNames.containsKey(AuthenticationType.INTERNAL) ) )
if (!(loginModuleNames.containsKey(AuthenticationType.OPENID) && loginModuleNames
.containsKey(AuthenticationType.INTERNAL)))
{
throw new RuntimeException("Multiple invalid authentication types present in Zanata configuration.");
}
}
else if( loginModuleNames.size() < 1)
else if (loginModuleNames.size() < 1)
{
throw new RuntimeException("At least one authentication type must be configured in Zanata configuration.");
}
Expand All @@ -136,7 +142,7 @@ public void applyLoggingConfiguration()
{
final Logger rootLogger = Logger.getRootLogger();

if( isEmailLogAppenderEnabled() )
if (isEmailLogAppenderEnabled())
{
// NB: This appender uses Seam's email configuration (no need for host or port)
smtpAppenderInstance.setName(EMAIL_APPENDER_NAME);
Expand Down Expand Up @@ -170,13 +176,14 @@ public String getServerPath()
{
String configuredValue = databaseBackedConfig.getServerHost();
// Try to determine a server path if one is not configured
if( configuredValue == null )
if (configuredValue == null)
{
HttpServletRequest request = ServletContexts.instance().getRequest();
if( request != null )
if (request != null)
{
configuredValue =
request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath();
}
}
return configuredValue;
Expand Down Expand Up @@ -217,9 +224,10 @@ public String getFromEmailAddr()
}

// Finally, just throw an Exception
if( emailAddr == null )
if (emailAddr == null)
{
throw new RuntimeException("'From' email address has not been defined in either zanata.properties or Zanata setup");
throw new RuntimeException(
"'From' email address has not been defined in either zanata.properties or Zanata setup");
}
return emailAddr;
}
Expand All @@ -233,30 +241,30 @@ public String getHelpContent()
{
return databaseBackedConfig.getHelpContent();
}

public boolean isInternalAuth()
{
return this.loginModuleNames.containsKey( AuthenticationType.INTERNAL );
return this.loginModuleNames.containsKey(AuthenticationType.INTERNAL);
}

public boolean isOpenIdAuth()
{
return this.loginModuleNames.containsKey( AuthenticationType.OPENID );
return this.loginModuleNames.containsKey(AuthenticationType.OPENID);
}

public boolean isKerberosAuth()
{
return this.loginModuleNames.containsKey( AuthenticationType.KERBEROS );
return this.loginModuleNames.containsKey(AuthenticationType.KERBEROS);
}

public boolean isJaasAuth()
{
return this.loginModuleNames.containsKey( AuthenticationType.JAAS );
return this.loginModuleNames.containsKey(AuthenticationType.JAAS);
}
public String getLoginModuleName( AuthenticationType authType )

public String getLoginModuleName(AuthenticationType authType)
{
return this.loginModuleNames.get( authType );
return this.loginModuleNames.get(authType);
}

public boolean isDebug()
Expand All @@ -273,8 +281,8 @@ public String getVersion()
{
return version;
}
void setVersion( String version )

void setVersion(String version)
{
this.version = version;
}
Expand All @@ -283,8 +291,8 @@ public String getBuildTimestamp()
{
return buildTimestamp;
}
void setBuildTimestamp( String buildTimestamp )

void setBuildTimestamp(String buildTimestamp)
{
this.buildTimestamp = buildTimestamp;
}
Expand All @@ -296,20 +304,20 @@ public boolean getEnableCopyTrans()

public Set<String> getAdminUsers()
{
return new HashSet<String>( adminUsers );
return new HashSet<String>(adminUsers);
}

public boolean isEmailLogAppenderEnabled()
{
String strVal = databaseBackedConfig.getShouldLogEvents();

if(strVal == null)
if (strVal == null)
{
return false;
}
else
{
return Boolean.parseBoolean( strVal );
return Boolean.parseBoolean(strVal);
}
}

Expand Down Expand Up @@ -344,7 +352,7 @@ public String getEmailServerHost()
String host = jndiBackedConfig.getSmtpHostName();

// Default to localhost
if( host == null )
if (host == null)
{
host = "localhost";
}
Expand All @@ -356,7 +364,7 @@ public int getEmailServerPort()
String port = jndiBackedConfig.getSmtpPort();

// Default to 25
if( port == null )
if (port == null)
{
port = "25";
}
Expand All @@ -375,23 +383,36 @@ public String getEmailServerPassword()

public boolean useEmailServerTls()
{
return jndiBackedConfig.getSmtpUsesTls() != null ? Boolean.parseBoolean(jndiBackedConfig.getSmtpUsesTls()) : false;
return jndiBackedConfig.getSmtpUsesTls() != null ? Boolean.parseBoolean(jndiBackedConfig.getSmtpUsesTls())
: false;
}

public boolean useEmailServerSsl()
{
return jndiBackedConfig.getStmpUsesSsl() != null ? Boolean.parseBoolean(jndiBackedConfig.getStmpUsesSsl()) : false;
return jndiBackedConfig.getStmpUsesSsl() != null ? Boolean.parseBoolean(jndiBackedConfig.getStmpUsesSsl())
: false;
}

public String getWebAssetsStyleUrl()
{
if (StringUtils.isEmpty(webAssetsStyleUrl))
{
webAssetsStyleUrl = String.format("%s/%s/assets/css/style.css", getBaseWebAssetsUrl(), webAssetsVersion);
}
return webAssetsStyleUrl;
}

public String getWebAssetsUrl()
{
return String.format("%s/%s/assets/css/style.css",
Objects.firstNonNull(jndiBackedConfig.getWebAssetsUrlBase(), "//assets-zanata.rhcloud.com"), webAssetsVersion);
if (StringUtils.isEmpty(webAssetsUrl))
{
webAssetsUrl = String.format("%s/%s", getBaseWebAssetsUrl(), webAssetsVersion);
}
return webAssetsUrl;
}
public String getBaseWebAssetsUrl()

private String getBaseWebAssetsUrl()
{
return String.format("%s/%s",
Objects.firstNonNull(jndiBackedConfig.getWebAssetsUrlBase(), "//assets-zanata.rhcloud.com"), webAssetsVersion);
return Objects.firstNonNull(jndiBackedConfig.getWebAssetsUrlBase(), "//assets-zanata.rhcloud.com");
}
}
Expand Up @@ -68,7 +68,7 @@ public class ActivityAction implements Serializable
@In(required = false, value = JpaIdentityStore.AUTHENTICATED_USER)
private HAccount authenticatedAccount;

private final int ACTIVITY_COUNT_PER_LOAD = 5;
private final int ACTIVITY_COUNT_PER_LOAD = 1;
private final int MAX_ACTIVITIES_COUNT_PER_PAGE = 20;

private final Date now = new Date();
Expand Down
Expand Up @@ -24,6 +24,8 @@
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;

import org.apache.commons.lang.time.DateUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
Expand All @@ -41,11 +43,9 @@
import org.zanata.dao.TextFlowTargetDAO;
import org.zanata.events.DocumentUploadedEvent;
import org.zanata.events.TextFlowTargetStateEvent;
import org.zanata.exception.ZanataServiceException;
import org.zanata.model.Activity;
import org.zanata.model.HDocument;
import org.zanata.model.HPerson;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HTextFlow;
import org.zanata.model.HTextFlowTarget;
import org.zanata.model.HasEntityType;
Expand Down Expand Up @@ -74,6 +74,9 @@ public class ActivityServiceImpl implements ActivityService

@In
private ProjectIterationDAO projectIterationDAO;

@In
private EntityManager entityManager;

@Override
public Activity findActivity(long actorId, EntityType contextType, long contextId, ActivityType actionType, Date actionTime)
Expand Down Expand Up @@ -119,30 +122,9 @@ public void logActivity(HPerson actor, HasEntityType context, HasEntityType targ
}

@Override
public Object getEntity(EntityType entityType, long entityId) throws ZanataServiceException
public Object getEntity(EntityType entityType, long entityId)
{
Object result = null;

if (entityType == EntityType.HDocument)
{
HDocument document = documentDAO.getById(entityId);
result = (entityType.getEntityClass().cast(document));
}
else if (entityType == EntityType.HProjectIteration)
{
HProjectIteration projectVersion = projectIterationDAO.findById(entityId, false);
result = (entityType.getEntityClass().cast(projectVersion));
}
else if (entityType == EntityType.HTexFlowTarget)
{
HTextFlowTarget target = textFlowTargetDAO.findById(entityId, false);
result = (entityType.getEntityClass().cast(target));
}
else
{
throw new ZanataServiceException("Unsupported entity type");
}
return result;
return entityManager.find(entityType.getEntityClass(), entityId);
}

/**
Expand Down
Expand Up @@ -13,13 +13,13 @@
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>#{messages['jsf.PageTitle']}</title>
<link rel="shortcut icon" href="#{applicationConfiguration.baseWebAssetsUrl}/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="#{applicationConfiguration.webAssetsUrl}/favicon.ico" type="image/x-icon" />

<link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/fontello/css/fontello.css"/>
<link type="text/css" rel="stylesheet" href="#{applicationConfiguration.webAssetsUrl}"/>
<link type="text/css" rel="stylesheet" href="#{applicationConfiguration.webAssetsStyleUrl}"/>
<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,400italic"/>

<link type="text/css" rel="stylesheet" href="#{applicationConfiguration.baseWebAssetsUrl}/assets/css/application.css"/>
<link type="text/css" rel="stylesheet" href="#{applicationConfiguration.webAssetsUrl}/assets/css/application.css"/>

<script src="codemirror-compressed.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="codemirror.css"/>
Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/webapp/WEB-INF/template/banner.xhtml
Expand Up @@ -14,7 +14,7 @@

<h1 class="header__title heading--sub">
<s:link view="/home.xhtml" propagation="none">
<img class="header__site-logo" src="#{applicationConfiguration.baseWebAssetsUrl}/logo.svg"/>
<img class="header__site-logo" src="#{applicationConfiguration.webAssetsUrl}/logo.svg"/>
#{messages['jsf.Zanata']}
</s:link>
</h1>
Expand Down
6 changes: 3 additions & 3 deletions zanata-war/src/main/webapp/WEB-INF/template/template.xhtml
Expand Up @@ -26,10 +26,10 @@
<meta name="viewport" content="width=device-width, minimum-scale=1.0" />
<meta http-equiv="cleartype" content="on" />

<link rel="shortcut icon" href="#{applicationConfiguration.baseWebAssetsUrl}/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="#{applicationConfiguration.webAssetsUrl}/favicon.ico" type="image/x-icon" />

<!--[if gt IE 8]><!-->
<link type="text/css" rel="stylesheet" href="#{applicationConfiguration.webAssetsUrl}" />
<link type="text/css" rel="stylesheet" href="#{applicationConfiguration.webAssetsStyleUrl}" />
<!--<![endif]-->

<!--[if (lt IE 9) & (!IEMobile)]>
Expand Down Expand Up @@ -66,7 +66,7 @@
<ui:include src="piwik.xhtml"/>

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="#{applicationConfiguration.baseWebAssetsUrl}/assets/js/script.js"></script>
<script src="#{applicationConfiguration.webAssetsUrl}/assets/js/script.js"></script>
</h:body>
</html>
</f:view>

0 comments on commit 3641a82

Please sign in to comment.