package com.dteknoloji.service;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.dteknoloji.config.GlobalSettings;
import com.dteknoloji.domain.Beacon;
import com.dteknoloji.repository.beacon.BeaconRepository;
import com.dteknoloji.repository.beacon.BeaconSpecifications;

/*
 **************************
 * Copyright (c) 2014     *
 *                        *
 * This code belongs to:  *
 *                        *
 * Ahmet Emre Ünal        *
 * S001974                *
 *                        *
 * aemreunal@gmail.com    *
 * emre.unal@ozu.edu.tr   *
 *                        *
 * aemreunal.com          *
 **************************
 */

@Transactional
@Service
public class BeaconService {
    @Autowired
    private BeaconRepository repository;

    public Beacon save(Beacon beacon) {
        return repository.save(beacon);
    }

    public List<Beacon> findAll() {
        if (GlobalSettings.DEBUGGING) {
            System.out.println("Finding all beacons");
        }

        List<Beacon> beaconList = new ArrayList<Beacon>();

        for (Beacon beacon : repository.findAll()) {
            beaconList.add(beacon);
        }

        return beaconList;
    }

    public List<Beacon> findBeaconsBySpecs(String uuid, String major, String minor) {
        if (GlobalSettings.DEBUGGING) {
            System.out.println("Finding beacons with UUID = \'" + uuid + "\' major = \'" + major + "\' minor = \'" + minor + "\'");
        }

        return repository.findAll(BeaconSpecifications.beaconWithSpecification(uuid, major, minor));
    }

    public Beacon findById(Long id) {
        if (GlobalSettings.DEBUGGING) {
            System.out.println("Finding beacon with ID = \'" + id + "\'");
        }

        return repository.findOne(id);
    }

    public boolean delete(Long id) {
        if (GlobalSettings.DEBUGGING) {
            System.out.println("Deleting beacon with ID = \'" + id + "\'");
        }

        if (id != null) {
            repository.delete(id);
            return true;
        } else {
            return false;
        }
    }

}

@@ -945,90 +945,341 @@
     
-public Beacon save(Beacon beacon) %7B%0A        return repository.save(beacon);%0A    %7D%0A
+/**%0A     * Saves/updates the given beacon%0A     *%0A     * @param beacon The beacon to save/update%0A     * @return The saved/updated beacon%0A     */%0A    public Beacon save(Beacon beacon) %7B%0A        return repository.save(beacon);%0A    %7D%0A%0A    /**%0A     * Returns the list of all the beacons%0A     *%0A     * @return A list of all beacons%0A     */
 %0A   
@@ -1603,32 +1603,318 @@
 conList;%0A    %7D%0A%0A
+    /**%0A     * Finds beacons conforming to given specifications%0A     *%0A     * @param uuid  The UUID field constraint%0A     * @param major The Major field constraint%0A     * @param minor The Minor field constraint%0A     * @return The list of beacons conforming to given constraints%0A     */%0A
     public List%3C
@@ -2266,32 +2266,188 @@
 minor));%0A    %7D%0A%0A
+    /**%0A     * Finds the beacon with the given ID%0A     *%0A     * @param id The ID of the beacon to search for%0A     * @return The beacon with that ID%0A     */%0A
     public Beaco
@@ -2636,24 +2636,192 @@
 id);%0A    %7D%0A%0A
+    /**%0A     * Deletes the beacon with the given ID%0A     *%0A     * @param id The ID of the beacon to delete%0A     * @return Whether the beacon was deleted or not%0A     */%0A
     public b

Add JavaDoc