| | |
| | | package de.uhilger.mediaz.api; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import de.uhilger.mediaz.App; |
| | |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * HttpHandler fuer die Ablage von Entitaeten der Mediazentrale |
| | | * HttpHandler fuer die Verwaltung von Entitaeten der Mediazentrale |
| | | * |
| | | * @author Ulrich Hilger |
| | | * @version 1, 5.4.2021 |
| | |
| | | } |
| | | |
| | | private String neu(HttpExchange e) throws IOException { |
| | | return schreiben(e, false); |
| | | } |
| | | |
| | | private String aendern(HttpExchange e) throws IOException { |
| | | return schreiben(e, true); |
| | | } |
| | | |
| | | private String schreiben(HttpExchange e, boolean overwrite) throws IOException { |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(App.getRs(Server.RB_SLASH)); |
| | | String type = elems[elems.length - 1]; |
| | |
| | | logger.log(Level.INFO, "type: {0}", type); |
| | | Object o = gson.fromJson(body, fs.typeFromName(type).getType()); |
| | | if(o instanceof Entity) { |
| | | Object antwortObjekt = fs.write((Entity) o); |
| | | Object antwortObjekt = fs.write((Entity) o, overwrite); |
| | | if(antwortObjekt instanceof File) { |
| | | File file = (File) antwortObjekt; |
| | | logger.log(Level.INFO, "Datei {0} geschrieben.", file.getAbsolutePath()); |
| | | filename = file.getName(); |
| | | return type + FileHandler.STR_BLANK + filename; |
| | | } |
| | | } |
| | | return type + FileHandler.STR_BLANK + filename; |
| | | return type + FileHandler.STR_BLANK + " Operation 'neu' fuer bereits existierende Entitaet."; |
| | | } |
| | | |
| | | /* |
| | | private String aendern(HttpExchange e) throws IOException { |
| | | return neu(e); // einstweilen wird einfach ueberschrieben |
| | | } |
| | | */ |
| | | |
| | | private boolean loeschen(HttpExchange e) { |
| | | String path = e.getRequestURI().toString(); |
| | |
| | | sb.append("}"); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | |
| | | private String bodyLesen(HttpExchange e) throws IOException { |
| | | InputStream is = e.getRequestBody(); |