Skip to content

Commit

Permalink
#3 Pushing data into logon table (if table exist).
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Mar 2, 2016
1 parent b854695 commit 8e472b5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public class ActivitiesResource {
private static final Logger log = getLogger(ActivitiesResource.class);

private final ObjectMapper mapper;
private final ActivitiesService activitiesService;

@Autowired
public ActivitiesResource(ObjectMapper mapper) {
public ActivitiesResource(ObjectMapper mapper, ActivitiesService activitiesService) {
this.mapper = mapper;
this.activitiesService = activitiesService;
}

//Available at http://localhost:4901/reporter/observe/activities/{prefix}
Expand All @@ -54,7 +56,8 @@ public Response addObservationActivity(@PathParam("prefix") String prefix, Strin
return Response.status(Response.Status.NOT_ACCEPTABLE).entity("Error converting to requested format.").build();
}

long updatedCount = observedActivities.size(); //writeOperations.addObservations(prefix,observedMethods);
// long updatedCount = observedActivities.size(); //writeOperations.addObservations(prefix,observedMethods);
long updatedCount = activitiesService.updateActivities(prefix,observedActivities);
String message = "added " + updatedCount + " observedMethods.";
Writer strWriter = new StringWriter();
try {
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/org/valuereporter/activity/ActivitiesService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
package org.valuereporter.activity;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Created by t-blind5-01 on 02.03.2016.
*/
@Service
public class ActivitiesService {
private static final Logger log = getLogger(ActivitiesService.class);

private final ActivitiesDao activitiesDao;

@Autowired
public ActivitiesService(ActivitiesDao activitiesDao) {
this.activitiesDao = activitiesDao;
}

public long updateActivities(String prefix, List<ObservedActivity> observedActivities) {
long updatedActivities = 0;
if (observedActivities != null && observedActivities.size() > 0) {
log.trace("Try to update {} activities for {}", observedActivities.size(), prefix);
//TODO split into separate lambda expressions depending on activity.name
ObservedActivity activity = observedActivities.get(0);
String tableName = activity.getName();
Map<String, Object> data = activity.getData();
if (data != null && data.keySet() != null) {
Set<String> keys = data.keySet();
ArrayList<String> columnNames = new ArrayList<>(keys.size());
for (String key : keys) {
columnNames.add(key);
}
updatedActivities = activitiesDao.insertActivities(tableName, columnNames, observedActivities);
}
}
return updatedActivities;
}
}

0 comments on commit 8e472b5

Please sign in to comment.