| /******************************************************************************** |
| * Copyright (c) 2018 Mettenmeier GmbH |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| package org.eclipse.openk.sp.rest; |
| |
| import java.util.Date; |
| import java.util.List; |
| |
| import javax.validation.Valid; |
| import javax.ws.rs.Consumes; |
| import javax.ws.rs.GET; |
| import javax.ws.rs.HeaderParam; |
| import javax.ws.rs.PUT; |
| import javax.ws.rs.Path; |
| import javax.ws.rs.PathParam; |
| import javax.ws.rs.Produces; |
| import javax.ws.rs.core.MediaType; |
| import javax.ws.rs.core.Response; |
| |
| import org.apache.log4j.Logger; |
| import org.eclipse.openk.common.Globals; |
| import org.eclipse.openk.resources.BaseResource; |
| import org.eclipse.openk.sp.controller.CalendarController; |
| import org.eclipse.openk.sp.dto.CalendarDayDto; |
| import org.eclipse.openk.sp.util.DateHelper; |
| import org.eclipse.openk.sp.util.FileHelper; |
| import org.springframework.beans.factory.annotation.Autowired; |
| |
| import io.swagger.annotations.ApiParam; |
| |
| @Path("calendar") |
| @Produces(MediaType.APPLICATION_JSON) |
| @Consumes(MediaType.APPLICATION_JSON) |
| public class CalendarRestService extends BaseResource { |
| |
| @Autowired |
| private CalendarController calendarController; |
| |
| public CalendarRestService() { |
| super(Logger.getLogger(CalendarRestService.class.getName()), new FileHelper()); |
| } |
| |
| @GET |
| @Path("/list") |
| public Response getCalendarDays( |
| @ApiParam(name = "Authorization", value = "JWT Token", required = true) @HeaderParam(value = Globals.KEYCLOAK_AUTH_TAG) String jwt) { |
| |
| ModifyingInvokable<List<CalendarDayDto>> invokable = modusr -> calendarController.getCalendarDays(); |
| |
| String[] securityRoles = Globals.getAllRolls(); |
| |
| return invokeRunnable(jwt, securityRoles, invokable); |
| } |
| |
| @GET |
| @Path("/selectionlist") |
| public Response getCalendarDaySelection( |
| @ApiParam(name = "Authorization", value = "JWT Token", required = true) @HeaderParam(value = Globals.KEYCLOAK_AUTH_TAG) String jwt) { |
| |
| return getCalendarDays(jwt); |
| } |
| |
| @GET |
| @Path("/{id}") |
| public Response getCalendarDay(@PathParam("id") Long id, |
| @ApiParam(name = "Authorization", value = "JWT Token", required = true) @HeaderParam(value = Globals.KEYCLOAK_AUTH_TAG) String jwt) { |
| |
| ModifyingInvokable<CalendarDayDto> invokable = modusr -> calendarController.getCalendarDay(id); |
| |
| String[] securityRoles = Globals.getAllRolls(); |
| |
| // return response |
| return invokeRunnable(jwt, securityRoles, invokable); |
| |
| } |
| |
| @PUT |
| @Path("/save") |
| public Response saveCalendarDay( |
| @ApiParam(name = "Authorization", value = "JWT Token", required = true) @HeaderParam(value = Globals.KEYCLOAK_AUTH_TAG) String jwt, |
| @Valid CalendarDayDto calendarDayDto) { |
| |
| Date d = DateHelper.addHoursToDate(calendarDayDto.getDateIndex(),5); |
| calendarDayDto.setDateIndex(d); |
| ModifyingInvokable<CalendarDayDto> invokable = modusr -> calendarController.saveCalendarDay(calendarDayDto); |
| |
| String[] securityRoles = { Globals.KEYCLOAK_ROLE_BP_SACHBEARBEITER, Globals.KEYCLOAK_ROLE_BP_ADMIN }; |
| |
| // return response |
| return invokeRunnable(jwt, securityRoles, invokable); |
| } |
| |
| @PUT |
| @Path("/delete") |
| public Response deleteCalendarDay( |
| @ApiParam(name = "Authorization", value = "JWT Token", required = true) @HeaderParam(value = Globals.KEYCLOAK_AUTH_TAG) String jwt, |
| CalendarDayDto calendarDayDto) { |
| |
| ModifyingInvokable<CalendarDayDto> invokable = modusr -> calendarController.deleteCalendarDay(calendarDayDto); |
| |
| String[] securityRoles = { Globals.KEYCLOAK_ROLE_BP_SACHBEARBEITER, Globals.KEYCLOAK_ROLE_BP_ADMIN }; |
| |
| // return response |
| return invokeRunnable(jwt, securityRoles, invokable); |
| } |
| |
| } |