Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Filter same activities (issue #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed Dec 18, 2012
1 parent 538f9ce commit 6ac3f55
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
4 changes: 2 additions & 2 deletions buildNumber.properties
@@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Tue Dec 11 17:18:39 CET 2012
buildNumber=68
#Wed Dec 19 00:17:10 CET 2012
buildNumber=73
Expand Up @@ -133,6 +133,10 @@ public void onSuccess(final FindActivityResult result)
{
displayString.append(": ").append(activity.getDescription());
}
if (activity.getProject() != null)
{
displayString.append(", (Project: ").append(activity.getProject().getName()).append(")");
}
NamedModelSuggestion<Activity> suggestion = new NamedModelSuggestion<Activity>(activity,
activity.getName(), highlighter.highlight(displayString.toString()));
suggestions.add(suggestion);
Expand Down
Expand Up @@ -7,6 +7,7 @@
import name.pehl.karaka.server.activity.control.ActivityIndexSearch;
import name.pehl.karaka.server.activity.control.ActivityRepository;
import name.pehl.karaka.server.activity.entity.Activity;
import name.pehl.karaka.server.activity.entity.SameActivity;
import name.pehl.karaka.server.settings.control.CurrentSettings;
import name.pehl.karaka.server.settings.entity.Settings;
import name.pehl.karaka.shared.model.Activities;
Expand Down Expand Up @@ -491,18 +492,18 @@ private Response addLinksForYearMonthDay(Activities activities, DateMidnight yea
@NoCache
public List<name.pehl.karaka.shared.model.Activity> findByName(@QueryParam("q") String query)
{
List<name.pehl.karaka.shared.model.Activity> result = new ArrayList<name.pehl.karaka.shared.model.Activity>();
Map<SameActivity, name.pehl.karaka.shared.model.Activity> activities = new HashMap<SameActivity, name.pehl.karaka.shared.model.Activity>();
Results<ScoredDocument> results = indexSearch.search(query);
for (ScoredDocument scoredDocument : results)
{
Long id = Long.valueOf(scoredDocument.getId());
Activity activity = repository.get(id);
if (activity != null)
{
result.add(activityConverter.toModel(activity));
activities.put(new SameActivity(activity), activityConverter.toModel(activity));
}
}
return result;
return new ArrayList<name.pehl.karaka.shared.model.Activity>(activities.values());
}


Expand All @@ -513,10 +514,13 @@ public List<name.pehl.karaka.shared.model.Activity> findByName(@QueryParam("q")
public Response minutesForCurrentMonthWeekAndDay()
{
DateMidnight now = now(settings.get().getTimeZone());
Duration currentMonth = minutes(repository.findByYearMonth(now.year().get(), now.monthOfYear().get()));
Duration currentWeek = minutes(repository.findByYearWeek(now.year().get(), now.weekOfWeekyear().get()));
Duration today = minutes(repository.findByYearMonthDay(now.year().get(), now.monthOfYear().get(), now
.dayOfMonth().get()));
int year = now.year().get();
int month = now.monthOfYear().get();
int week = now.weekOfWeekyear().get();
int day = now.dayOfMonth().get();
Duration currentMonth = minutes(repository.findByYearMonth(year, month));
Duration currentWeek = minutes(repository.findByYearWeek(year, week));
Duration today = minutes(repository.findByYearMonthDay(year, month, day));
Durations durations = new Durations(currentMonth, currentWeek, today);

String url = uriInfo.getAbsolutePath().toASCIIString();
Expand Down
@@ -0,0 +1,47 @@
package name.pehl.karaka.server.activity.entity;

import name.pehl.karaka.server.project.entity.Project;

/**
* Compares activities by name, description and project instead by id. Can be used as key in maps to filter
* activities.
* @author Harald Pehl
*/
public class SameActivity
{
private final String name;
private final String description;
private final Project project;


public SameActivity(final Activity activity)
{
this.name = activity.getName();
this.description = activity.getDescription();
this.project = activity.getProject() != null ? activity.getProject().get() : null;
}

@Override
public boolean equals(final Object o)
{
if (this == o) { return true; }
if (!(o instanceof SameActivity)) { return false; }

SameActivity that = (SameActivity) o;

if (!name.equals(that.name)) { return false; }
if (description != null ? !description.equals(that.description) : that.description != null) { return false; }
if (project != null ? !project.equals(that.project) : that.project != null) { return false; }

return true;
}

@Override
public int hashCode()
{
int result = name.hashCode();
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (project != null ? project.hashCode() : 0);
return result;
}
}

0 comments on commit 6ac3f55

Please sign in to comment.