BrightSide Workbench Full Report + Source Code
org.turro.contacts.comment.AboutVM Class Reference

Public Member Functions

void init (@ExecutionArgParam("contact") Contact contact)
 
void setContact (@BindingParam("contact") Object contact)
 
void setWeb (@BindingParam("web") String web)
 
void setTrade (@BindingParam("trade") String trade)
 
void setImage (@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) throws IOException
 
void save ()
 
void update ()
 
Contact getContact ()
 
String getImage ()
 
String getWeb ()
 
String getTrade ()
 
boolean isInRole (String role)
 
List< String > getLangModel ()
 
List< ContactgetContactsModel ()
 
List< AboutWrappergetAboutModel ()
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 69 of file AboutVM.java.

Member Function Documentation

◆ getAboutModel()

List<AboutWrapper> org.turro.contacts.comment.AboutVM.getAboutModel ( )

Definition at line 222 of file AboutVM.java.

222  {
223  if(model == null) {
224  model = new ArrayList<>();
225  getLangModel().forEach((lang) -> {
226  boolean done = false;
227  for(Comment comment : contact.getComments()) {
228  if(comment.getComment().startsWith("#cv" + lang)) {
229  AboutWrapper wrapper = new AboutWrapper(lang, chooseLabel(lang), comment);
230  model.add(wrapper);
231  done = true;
232  }
233  }
234  if (!done) {
235  AboutWrapper wrapper = new AboutWrapper(lang, chooseLabel(lang), new Comment());
236  model.add(wrapper);
237  }
238  });
239  }
240  return model;
241  }
Set< Comment > getComments()
Definition: Contact.java:415
Here is the call graph for this function:

◆ getContact()

Contact org.turro.contacts.comment.AboutVM.getContact ( )

Definition at line 167 of file AboutVM.java.

167  {
168  return contact;
169  }

◆ getContactsModel()

List<Contact> org.turro.contacts.comment.AboutVM.getContactsModel ( )

Definition at line 202 of file AboutVM.java.

202  {
203  ContactList list = new ContactList();
204  list.addAll(contact.getProfile()
205  .getCurrentCompanies().stream()
206  .filter(r -> r.getRelation().isResponsible())
207  .map(r -> (Contact) r.getRelation().getBusiness())
208  .collect(Collectors.toList()));
209  if(!list.isEmpty()) {
210  setContact(list.get(0));
211  } else {
212  Application.getApplication().sendRedirect("/user");
213  }
214  return list;
215  }
void setContact(@BindingParam("contact") Object contact)
Definition: AboutVM.java:83
Here is the call graph for this function:

◆ getImage()

String org.turro.contacts.comment.AboutVM.getImage ( )

Definition at line 171 of file AboutVM.java.

171  {
172  FileAttach fileAttach = new FileAttach(ContactsPU.getObjectPath(contact));
173  String faceFile = fileAttach.getPublicFile("/profile/face.png", false);
174  if(!Strings.isBlank(faceFile)) {
175  return faceFile + "?" + IdGenerator.generateHex();
176  } else {
177  return null;
178  }
179  }
Here is the call graph for this function:

◆ getLangModel()

List<String> org.turro.contacts.comment.AboutVM.getLangModel ( )

Definition at line 193 of file AboutVM.java.

193  {
194  if(langs == null) {
195  langs = new ArrayList<>();
196  langs.add("#"); // default
197  langs.addAll(Arrays.asList(ElephantContext.getSiteLocales().split(" *, *")));
198  }
199  return langs;
200  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTrade()

String org.turro.contacts.comment.AboutVM.getTrade ( )

Definition at line 185 of file AboutVM.java.

185  {
186  return Contacts.getContact(contact).getConnector(IUser.CONNECTOR_TRADE);
187  }
Here is the call graph for this function:

◆ getWeb()

String org.turro.contacts.comment.AboutVM.getWeb ( )

Definition at line 181 of file AboutVM.java.

181  {
182  return Contacts.getContact(contact).getConnector("Web");
183  }
Here is the call graph for this function:

◆ init()

void org.turro.contacts.comment.AboutVM.init ( @ExecutionArgParam("contact") Contact  contact)

Definition at line 76 of file AboutVM.java.

76  {
77  if(contact != null) this.contact = contact;
78  setContact(this.contact);
79  }
Here is the call graph for this function:

◆ isInRole()

boolean org.turro.contacts.comment.AboutVM.isInRole ( String  role)

Definition at line 189 of file AboutVM.java.

189  {
190  return Application.getApplication().isInRole(role);
191  }
Here is the call graph for this function:

◆ save()

void org.turro.contacts.comment.AboutVM.save ( )

Definition at line 142 of file AboutVM.java.

142  {
143  if(model != null) {
144  if(contact != null) {
145  for(AboutWrapper wrapper : model) {
146  if(wrapper.isNewComment() && !wrapper.isEmpty()) {
147  Comment comment = wrapper.getComment();
148  comment.setContact(contact);
149  comment.setModification(new Date());
150  contact.getComments().add(comment);
151  }
152  }
153  contact.checkEmptyness();
154  contact = new ContactsPU().saveObject(contact);
155  resetAboutModel();
156  sendNotification(contact);
157  Clients.showNotification(I_.get("Saved"));
158  }
159  }
160  }
Here is the call graph for this function:

◆ setContact()

void org.turro.contacts.comment.AboutVM.setContact ( @BindingParam("contact") Object  contact)

Definition at line 83 of file AboutVM.java.

83  {
84  if(contact instanceof Contact) {
85  this.contact = (Contact) contact;
86  }
87  model = null;
88  }
Here is the caller graph for this function:

◆ setImage()

void org.turro.contacts.comment.AboutVM.setImage ( @ContextParam(ContextType.BIND_CONTEXT) BindContext  ctx) throws IOException

Definition at line 111 of file AboutVM.java.

111  {
112  UploadEvent event = (UploadEvent) ctx.getTriggerEvent();
113  FileAttach fileAttach = new FileAttach(ContactsPU.getObjectPath(contact));
114  File newFile = new File(ElephantContext.getRealPath(fileAttach.getPublishable() + "/profile/face.png"));
115  if(!newFile.getParentFile().exists()) {
116  newFile.getParentFile().mkdirs();
117  }
118  try (FileOutputStream fos = new FileOutputStream(newFile)) {
119  Media media = event.getMedia();
120  if(media != null) {
121  if(media.inMemory()) {
122  fos.write(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
123  } else {
124  byte[] buffer = new byte[102400];
125  try (InputStream is = media.isBinary() ? media.getStreamData() : new ReaderInputStream(media.getReaderData())) {
126  int r;
127  while((r = is.read(buffer)) != -1) {
128  fos.write(buffer, 0, r);
129  }
130  }
131  }
132  }
133  } catch (FileNotFoundException ex) {
134  Logger.getLogger(AboutVM.class.getName()).log(Level.SEVERE, null, ex);
135  }
136  org.zkoss.lang.Threads.sleep(2000);
137  BindUtils.postNotifyChange(null, null, AboutVM.this, "image");
138  }
Here is the call graph for this function:

◆ setTrade()

void org.turro.contacts.comment.AboutVM.setTrade ( @BindingParam("trade") String  trade)

Definition at line 102 of file AboutVM.java.

102  {
103  if(!Strings.isBlank(trade)) {
104  Contacts.getContact(contact).setConnector(IUser.CONNECTOR_TRADE, trade);
105  } else {
106  Contacts.getContact(contact).setConnector(IUser.CONNECTOR_TRADE, null);
107  }
108  }
Here is the call graph for this function:

◆ setWeb()

void org.turro.contacts.comment.AboutVM.setWeb ( @BindingParam("web") String  web)

Definition at line 92 of file AboutVM.java.

92  {
93  if(!Strings.isBlank(web)) {
94  Contacts.getContact(contact).setConnector("Web", UrlCompose.fillWebGaps(web));
95  } else {
96  Contacts.getContact(contact).setConnector("Web", null);
97  }
98  }
Here is the call graph for this function:

◆ update()

void org.turro.contacts.comment.AboutVM.update ( )

Definition at line 163 of file AboutVM.java.

163  {
164  model = null;
165  }

The documentation for this class was generated from the following file: