BrightSide Workbench Full Report + Source Code
AttachLastActivity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.activity;
20 
21 import java.util.Date;
22 import java.util.function.Consumer;
23 import org.turro.attach.db.AttachPU;
24 import org.turro.attach.entity.Attachment;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.entities.IElephantEntity;
27 import org.turro.jpa.Dao;
28 import org.zkoss.lang.Strings;
29 
34 @LastActivity
35 public class AttachLastActivity implements ILastActivity {
36 
37  @Override
38  public EntityActivitySet getActivities(Date from, String entityPath, String type) {
40  getAttachments(entityPath, from, attachment -> {
41  IElephantEntity iee = attachment.getOwnerEntity();
43  attachment, iee.getPath(), attachment.getModification(), "Attached");
45  set.add(ela);
46  });
47  return set;
48  }
49 
50  @Override
51  public Object getMainEntity(Object entity) {
52  return null;
53  }
54 
55  public void getAttachments(String path, Date from, Consumer<Attachment> action) {
56  WhereClause wc = new WhereClause();
57  wc.addClause("select attachment from Attachment as attachment");
58  wc.addClause("where attachment.modification >= :date");
59  wc.addNamedValue("date", from);
60  if(!Strings.isBlank(path)) {
61  wc.addClause("and path like :path");
62  wc.addNamedValue("path", path + "%");
63  }
64  getDao().forEach(Attachment.class, wc, action);
65  }
66 
67  /* Dao */
68 
69  private Dao _dao;
70 
71  private Dao getDao() {
72  if(_dao == null) {
73  _dao = new AttachPU();
74  }
75  return _dao;
76  }
77 
78 }
void getAttachments(String path, Date from, Consumer< Attachment > action)
EntityActivitySet getActivities(Date from, String entityPath, String type)
void addNamedValue(String name, Object value)