BrightSide Workbench Full Report + Source Code
Faces.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.entities;
20 
21 import org.turro.elephant.context.ElephantContext;
22 import org.turro.file.Document;
23 import org.turro.plugin.contacts.IContact;
24 import org.turro.string.Strings;
25 
30 public class Faces {
31 
32  private final static String
33  PUBLIC = "/_internal/files",
34  FACE = "/profile/face.png";
35 
36  public String getPath() {
37  return getDocument().exists() ? createPath() : null;
38  }
39 
40  public String getWebPath() {
41  String path = getPath();
42  return Strings.isBlank(path) ? null :
44  }
45 
46  public String getUrl() {
47  String path = getPath();
48  return Strings.isBlank(path) ? null :
49  (ElephantContext.getServerUrl("http") + path);
50  }
51 
52  public Document getDocument() {
53  return Document.from(ElephantContext.getRealPath(createPath()));
54  }
55 
56  /* Utils */
57 
58  private String createPath() {
59  return PUBLIC + "/" + entityRoot + "/" + id + FACE;
60  }
61 
62  /* Factory */
63 
64  public static Faces of(IContact contact) {
65  return new Faces("contact", contact.getId());
66  }
67 
68  public static Faces of(String entityRoot, String id) {
69  return new Faces(entityRoot, id);
70  }
71 
72  private final String entityRoot, id;
73 
74  private Faces(String entityRoot, String id) {
75  this.entityRoot = entityRoot;
76  this.id = id;
77  }
78 
79 }
static String getServerUrl(String scheme)
Document getDocument()
Definition: Faces.java:52
static Faces of(IContact contact)
Definition: Faces.java:64
static Faces of(String entityRoot, String id)
Definition: Faces.java:68