001/**
002 * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational Community
003 * License, Version 2.0 (the "License"); you may not use this file except in
004 * compliance with the License. You may obtain a copy of the License at
005 *
006 * http://www.osedu.org/licenses/ECL-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
010 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
011 * License for the specific language governing permissions and limitations under
012 * the License.
013 */
014package org.kuali.mobility.computerlabs.service;
015
016import java.util.ArrayList;
017import java.util.Collection;
018import java.util.List;
019import javax.ws.rs.GET;
020import javax.ws.rs.Path;
021import javax.ws.rs.QueryParam;
022import org.apache.commons.collections.CollectionUtils;
023
024import org.apache.log4j.Logger;
025import org.kuali.mobility.computerlabs.dao.ComputerLabsDao;
026import org.kuali.mobility.computerlabs.entity.Lab;
027import org.kuali.mobility.computerlabs.entity.LabGroup;
028import org.kuali.mobility.computerlabs.entity.LabGroupImpl;
029import org.kuali.mobility.computerlabs.entity.LabImpl;
030import org.kuali.mobility.computerlabs.entity.Location;
031import org.kuali.mobility.computerlabs.entity.LocationImpl;
032import org.kuali.mobility.computerlabs.util.LabGroupTransform;
033import org.kuali.mobility.computerlabs.util.LabPredicate;
034import org.kuali.mobility.computerlabs.util.LabTransform;
035import org.kuali.mobility.computerlabs.util.LocationTransform;
036
037public class ComputerLabsServiceImpl implements ComputerLabsService {
038
039        private static final Logger LOG = Logger.getLogger(ComputerLabsServiceImpl.class);
040        private ComputerLabsDao dao;
041
042        public ComputerLabsDao getDao() {
043                return dao;
044        }
045
046        public void setDao(ComputerLabsDao dao) {
047                this.dao = dao;
048        }
049
050        @GET
051        @Path("/getLabGroups")
052        @Override
053        public List<LabGroupImpl> getLabGroups() {
054                List<LabGroupImpl> labGroups = new ArrayList<LabGroupImpl>();
055                CollectionUtils.collect( getDao().getLabGroups(), new LabGroupTransform(), labGroups);
056                return labGroups;
057        }
058
059        @GET
060        @Path("/getLabGroup")
061        @Override
062        public LabGroupImpl getLabGroup(@QueryParam(value="groupId") final String groupId) {
063                LabGroup myGroup = getDao().getLabGroup(groupId);
064                LabGroupTransform transform = new LabGroupTransform();
065                return transform.transform(myGroup);
066        }
067
068        @GET
069        @Path("/getLocations")
070        @Override
071        public List<LocationImpl> getLocations(@QueryParam(value="groupId") final String groupId) {
072                List<LocationImpl> locations = new ArrayList<LocationImpl>();
073                CollectionUtils.collect(getDao().getLocations(groupId), new LocationTransform(), locations);
074                return locations;
075        }
076
077//      @GET
078//      @Path("/getLocation")
079//      @Override
080//      public LocationImpl getLocation(@QueryParam(value = "locationId") final String locationId) {
081//              LocationImpl location = null;
082//              if (null != locationId) {
083//                      for (Location l : getDao().getLocations()) {
084//                              if ( locationId.equalsIgnoreCase( l.getName() ) ) {
085//                                      LocationTransform transform = new LocationTransform();
086//                                      location = transform.transform(l);
087//                              }
088//                      }
089//              }
090//              return location;
091//      }
092
093        @GET
094        @Path("/getLabs")
095        @Override
096        public List<LabImpl> getLabs(
097                        @QueryParam(value = "locationId") final String locationId,
098                        @QueryParam(value = "buildingCode") final String buildingCode) {
099                List<LabImpl> myLabs = new ArrayList<LabImpl>();
100                CollectionUtils.collect(getDao().getLabs(locationId, buildingCode), new LabTransform(), myLabs);
101                return myLabs;
102        }
103
104        @GET
105        @Path("/getLab")
106        @Override
107        public LabImpl getLab(@QueryParam(value = "labUID") final String labUid) {
108                LabTransform transform = new LabTransform();
109                return transform.transform(getDao().getLab(labUid));
110        }
111}