1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package org.opengrok.web.api.v1.controller; 24 import jakarta.inject.Inject; 25 import jakarta.validation.Valid; 26 import jakarta.ws.rs.Consumes; 27 import jakarta.ws.rs.GET; 28 import jakarta.ws.rs.POST; 29 import jakarta.ws.rs.PUT; 30 import jakarta.ws.rs.Path; 31 import jakarta.ws.rs.Produces; 32 import jakarta.ws.rs.core.MediaType; 33 import com.fasterxml.jackson.core.JsonProcessingException; 34 import com.fasterxml.jackson.databind.ObjectMapper; 35 import com.fasterxml.jackson.databind.util.StdDateFormat; 36 import org.opengrok.indexer.configuration.IndexTimestamp; 37 import org.opengrok.indexer.configuration.RuntimeEnvironment; 38 import org.opengrok.indexer.web.EftarFile; 39 import org.opengrok.indexer.logger.LoggerFactory; 40 import org.opengrok.indexer.web.PathDescription; 41 import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService; 42 43 import java.io.IOException; 44 import java.util.Date; 45 import java.util.Set; 46 import java.util.logging.Level; 47 import java.util.logging.Logger; 48 49 @Path("/system") 50 public class SystemController { 51 52 private final RuntimeEnvironment env = RuntimeEnvironment.getInstance(); 53 54 private static final Logger LOGGER = LoggerFactory.getLogger(SystemController.class); 55 56 @Inject 57 private SuggesterService suggester; 58 59 @PUT 60 @Path("/includes/reload") reloadIncludes()61 public void reloadIncludes() { 62 env.getIncludeFiles().reloadIncludeFiles(); 63 } 64 65 @POST 66 @Path("/pathdesc") 67 @Consumes(MediaType.APPLICATION_JSON) loadPathDescriptions(@alid final PathDescription[] descriptions)68 public void loadPathDescriptions(@Valid final PathDescription[] descriptions) throws IOException { 69 EftarFile ef = new EftarFile(); 70 ef.create(Set.of(descriptions), env.getDtagsEftarPath().toString()); 71 LOGGER.log(Level.INFO, "reloaded path descriptions with {0} entries", descriptions.length); 72 } 73 74 @GET 75 @Path("/indextime") 76 @Produces(MediaType.APPLICATION_JSON) getIndexTime()77 public String getIndexTime() throws JsonProcessingException { 78 Date date = new IndexTimestamp().getDateForLastIndexRun(); 79 ObjectMapper mapper = new ObjectMapper(); 80 // StdDateFormat is ISO8601 since jackson 2.9 81 mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true)); 82 return mapper.writeValueAsString(date); 83 } 84 } 85