Skip to content

Commit

Permalink
WIP: remove findbugs warning from zanata-war
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed May 3, 2017
1 parent ee445a3 commit ab1a8fd
Show file tree
Hide file tree
Showing 44 changed files with 401 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

package org.zanata.rest.service;

import java.io.Serializable;

/**
* Marker interface for REST Resource classes (used by org.zanata.util.JaxRSClassIndexProcessor)
*
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
public interface RestResource {
public interface RestResource extends Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class HLocale : ModelEntityBase, Serializable, HasUserFriendlyToString {
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
get() {
if (field == null) field = HashSet()
return field
return field!!
}

var pluralForms: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,36 @@ public class H2DocumentHistoryTrigger extends TriggerAdapter {
@Override
public void fire(Connection conn, ResultSet oldRow, ResultSet newRow)
throws SQLException {
log.debug("Executing HDocumentHistory trigger");
int oldRev = oldRow.getInt("revision");
int newRev = newRow.getInt("revision");
if (oldRev != newRev) {
log.debug("revision incremented from {} to {}. Executing trigger..",
oldRev, newRev);
PreparedStatement prep = conn.prepareStatement(
"INSERT INTO HDocumentHistory (document_id,revision,contentType,docId,locale,name,path,lastChanged,last_modified_by_id,obsolete) VALUES (?,?,?,?,?,?,?,?,?,?)");
prep.setObject(1, oldRow.getObject("id"));
prep.setObject(2, oldRow.getObject("revision"));
prep.setObject(3, oldRow.getObject("contentType"));
prep.setObject(4, oldRow.getObject("docId"));
prep.setObject(5, oldRow.getObject("locale"));
prep.setObject(6, oldRow.getObject("name"));
prep.setObject(7, oldRow.getObject("path"));
prep.setObject(8, oldRow.getObject("lastChanged"));
prep.setObject(9, oldRow.getObject("last_modified_by_id"));
prep.setObject(10, oldRow.getObject("obsolete"));
prep.execute();
} else {
log.warn(
"HDocument updated without incrementing revision... skipping trigger");
PreparedStatement prep = null;
try {
log.debug("Executing HDocumentHistory trigger");
int oldRev = oldRow.getInt("revision");
int newRev = newRow.getInt("revision");
if (oldRev != newRev) {
log.debug(
"revision incremented from {} to {}. Executing trigger..",
oldRev, newRev);
prep = conn.prepareStatement(
"INSERT INTO HDocumentHistory (document_id,revision,contentType,docId,locale,name,path,lastChanged,last_modified_by_id,obsolete) VALUES (?,?,?,?,?,?,?,?,?,?)");
prep.setObject(1, oldRow.getObject("id"));
prep.setObject(2, oldRow.getObject("revision"));
prep.setObject(3, oldRow.getObject("contentType"));
prep.setObject(4, oldRow.getObject("docId"));
prep.setObject(5, oldRow.getObject("locale"));
prep.setObject(6, oldRow.getObject("name"));
prep.setObject(7, oldRow.getObject("path"));
prep.setObject(8, oldRow.getObject("lastChanged"));
prep.setObject(9, oldRow.getObject("last_modified_by_id"));
prep.setObject(10, oldRow.getObject("obsolete"));
prep.execute();
} else {
log.warn(
"HDocument updated without incrementing revision... skipping trigger");
}
} finally {
if (prep != null) {
prep.close();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class ActivityAction implements Serializable {
@Authenticated
private HAccount authenticatedAccount;

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

private int activityPageIndex = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public void startCopyTrans(HProjectIteration iteration,

public void cancelCopyTrans(@Nonnull HProjectIteration iteration) {
if (isCopyTransRunning(iteration)) {
CopyTransProcessKey key = CopyTransProcessKey.getKey(iteration);
CopyTransTaskHandle handle =
this.getCopyTransProcessHandle(iteration);
handle.cancel(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class LanguageAction implements Serializable {
private String language;
private String searchTerm;
private HLocale locale;

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SE_BAD_FIELD")
private List<SelectablePerson> searchResults;
private AbstractListFilter<HLocaleMember> membersFilter =
new InMemoryListFilter<HLocaleMember>() {
Expand All @@ -129,8 +131,7 @@ public List<LanguageRequest> getRequests() {
if (identity == null) {
return Lists.newArrayList();
}
if (identity != null
&& identity.hasPermission(locale, "manage-language-team")) {
if (identity.hasPermission(locale, "manage-language-team")) {
return requestServiceImpl
.getPendingLanguageRequests(locale.getLocaleId());
}
Expand Down Expand Up @@ -236,8 +237,8 @@ public void saveSettings() {
if (!isValidPluralForms(hLocale.getPluralForms(), "pluralForms")) {
return;
}
hLocale.setDisplayName(hLocale.getDisplayName().trim());
hLocale.setNativeName(hLocale.getNativeName().trim());
hLocale.setDisplayName(StringUtils.trim(hLocale.getDisplayName()));
hLocale.setNativeName(StringUtils.trim(hLocale.getNativeName()));
localeDAO.makePersistent(getLocale());
facesMessages.addGlobal(
msgs.format("jsf.language.updated", getLocale().getLocaleId()));
Expand Down Expand Up @@ -429,7 +430,8 @@ private void savePermission(HLocaleMember member, String permissionDesc,
case Coordinator:
changedEvent = changedEvent.changedCoordinatorPermission(member);
break;

default:
break;
}
languageTeamPermissionChangedEvent.fire(changedEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.faces.application.FacesMessage;
import com.google.common.base.Strings;
import com.google.common.collect.Ordering;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang.StringUtils;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
Expand Down Expand Up @@ -161,6 +162,7 @@ protected boolean include(HProjectIteration elem,
private Map<HPerson, ListMultimap<HLocale, LocaleRole>> personLocaleRoles;
private List<HProjectIteration> projectVersions;
private Map<String, WordStatistic> statisticMap = Maps.newHashMap();
@SuppressFBWarnings( value = "SE_BAD_FIELD")
private final VersionComparator versionComparator =
new VersionComparator(getVersionSortingList());
private final java.util.concurrent.atomic.AtomicReference<Object> projectLastActivity =
Expand Down Expand Up @@ -228,7 +230,7 @@ private List<Activity> fetchProjectLastActivity() {

@Override
public Long apply(@Nullable HProjectIteration input) {
return input.getId();
return input != null ? input.getId(): null;
}
});
return activityServiceImpl.findLatestVersionActivitiesByUser(
Expand All @@ -250,7 +252,8 @@ public void sortVersionList() {
versionFilter.reset();
}

private class VersionComparator implements Comparator<HProjectIteration> {
private final class VersionComparator
implements Comparator<HProjectIteration> {
private SortingType sortingType;

public VersionComparator(SortingType sortingType) {
Expand Down Expand Up @@ -631,13 +634,18 @@ public Collection<String> rolesDisplayForLocale(HPerson person,
@Override
public String apply(
@Nullable Map.Entry<HLocale, Collection<LocaleRole>> entry) {
final String localeName =
entry.getKey().retrieveDisplayName();
final List<LocaleRole> sortedRoles =
LOCALE_ROLE_ORDERING.sortedCopy(entry.getValue());
final List<String> roleNames =
Lists.transform(sortedRoles, TO_DISPLAY_NAME);
return localeName + " " + Joiner.on(", ").join(roleNames);
if (entry != null) {
final String localeName =
entry.getKey().retrieveDisplayName();
final List<LocaleRole> sortedRoles =
LOCALE_ROLE_ORDERING
.sortedCopy(entry.getValue());
final List<String> roleNames =
Lists.transform(sortedRoles, TO_DISPLAY_NAME);
return localeName + " " +
Joiner.on(", ").join(roleNames);
}
return null;
}
};
private final Function<LocaleRole, String> TO_DISPLAY_NAME =
Expand All @@ -646,7 +654,7 @@ public String apply(
@Nullable
@Override
public String apply(@Nullable LocaleRole role) {
return localeRoleDisplayName(role);
return role != null ? localeRoleDisplayName(role): null;
}
};

Expand Down Expand Up @@ -703,7 +711,8 @@ public int getGlossarySize() {
public String apply(HLocale input) {
// To lowercase to prevent non-caps values appearing after
// all caps values (e.g. a appearing after Z)
return input.retrieveDisplayName().toLowerCase();
return input != null ?
input.retrieveDisplayName().toLowerCase() : null;
}
};
private static final Ordering<HLocale> LOCALE_NAME_ORDERING =
Expand Down Expand Up @@ -915,6 +924,7 @@ public PeopleFilterComparator getPeopleFilterComparator() {
return this.peopleFilterComparator;
}

@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
public List<Activity> getProjectLastActivity() {
Object value = this.projectLastActivity.get();
if (value == null) {
Expand Down
31 changes: 16 additions & 15 deletions server/zanata-war/src/main/java/org/zanata/action/SortingType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ public void setSelectedSortOption(SortOption selectedSortOption) {
this.selectedSortOption = selectedSortOption;
}

public enum SortOption {
PERCENTAGE("Percent translated", false),
HOURS("Hours remaining", false),
WORDS("Words remaining", false),
ALPHABETICAL("Alphabetical", true),
LAST_ACTIVITY("Last activity", false),
LAST_SOURCE_UPDATE("Last source updated", false),
LAST_TRANSLATED("Last translated", false),
LAST_UPDATED_BY_YOU("Last updated by you", false),
Entry("Entry", false),
LOCALE_ID("Locale code", true),
MEMBERS("Members", true),
CREATED_DATE("Created date", true),
NAME("Name", true),
ROLE("Role", true);
public static final class SortOption {
public final static SortOption PERCENTAGE = new SortOption("Percent translated", false);
public final static SortOption HOURS = new SortOption("Hours remaining", false);
public final static SortOption WORDS = new SortOption("Words remaining", false);
public final static SortOption ALPHABETICAL = new SortOption("Alphabetical", true);
public final static SortOption LAST_ACTIVITY = new SortOption("Last activity", false);
public final static SortOption LAST_SOURCE_UPDATE = new SortOption("Last source updated", false);
public final static SortOption LAST_TRANSLATED = new SortOption("Last translated", false);
public final static SortOption LAST_UPDATED_BY_YOU = new SortOption("Last updated by you", false);
public final static SortOption Entry = new SortOption("Entry", false);
public final static SortOption LOCALE_ID = new SortOption("Locale code", true);
public final static SortOption MEMBERS = new SortOption("Members", true);
public final static SortOption CREATED_DATE = new SortOption("Created date", true);
public final static SortOption NAME = new SortOption("Name", true);
public final static SortOption ROLE = new SortOption("Role", true);

String display;
boolean ascending; // default sort

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public int hashCode() {
}
}

private static class TMComparator implements Comparator<TransMemory> {
private static class TMComparator implements Comparator<TransMemory>, Serializable {
private SortingType sortingType;

public TMComparator(SortingType sortingType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,18 @@ public int compare(HLocale o1, HLocale o2) {
wordStatistic2 = statisticMap.get(new VersionLocaleKey(
selectedVersionId, o2.getLocaleId()));
}
switch (selectedSortOption) {
case PERCENTAGE:
if (selectedSortOption.getDisplay()
.equals(SortingType.SortOption.PERCENTAGE.getDisplay())) {
return Double.compare(wordStatistic1.getPercentTranslated(),
wordStatistic2.getPercentTranslated());

case HOURS:
} else if (selectedSortOption.getDisplay()
.equals(SortingType.SortOption.HOURS.getDisplay())) {
return Double.compare(wordStatistic1.getRemainingHours(),
wordStatistic2.getRemainingHours());

case WORDS:
} else if (selectedSortOption.getDisplay()
.equals(SortingType.SortOption.WORDS.getDisplay())) {
return Double.compare(wordStatistic1.getUntranslated(),
wordStatistic2.getUntranslated());

}
} else {
return o1.retrieveDisplayName()
Expand Down Expand Up @@ -260,19 +259,18 @@ public int compare(HProjectIteration o1, HProjectIteration o2) {
wordStatistic1 = getStatisticForProject(o1.getId());
wordStatistic2 = getStatisticForProject(o2.getId());
}
switch (selectedSortOption) {
case PERCENTAGE:
if (selectedSortOption.getDisplay()
.equals(SortingType.SortOption.PERCENTAGE.getDisplay())) {
return Double.compare(wordStatistic1.getPercentTranslated(),
wordStatistic2.getPercentTranslated());

case HOURS:
} else if (selectedSortOption.getDisplay()
.equals(SortingType.SortOption.HOURS.getDisplay())) {
return Double.compare(wordStatistic1.getRemainingHours(),
wordStatistic2.getRemainingHours());

case WORDS:
} else if (selectedSortOption.getDisplay()
.equals(SortingType.SortOption.WORDS.getDisplay())) {
return Double.compare(wordStatistic1.getUntranslated(),
wordStatistic2.getUntranslated());

}
} else {
return ComparatorUtil.compareStringIgnoreCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.zanata.webtrans.shared.model.WorkspaceId;

import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;

/**
* @author Patrick Huang
Expand All @@ -42,10 +43,10 @@ public class TransMemoryMergeEvent {
private final Date endTime;

public TransMemoryMergeEvent(WorkspaceId workspaceId,
Date startTime, String username, EditorClientId editorClientId,
@NotNull Date startTime, String username, EditorClientId editorClientId,
DocumentId documentId, long total, @Nullable Date endTime) {
this.workspaceId = workspaceId;
this.startTime = startTime;
this.startTime = new Date(startTime.getTime());
this.username = username;
this.editorClientId = editorClientId;
this.documentId = documentId;
Expand Down
Loading

0 comments on commit ab1a8fd

Please sign in to comment.