BrightSide Workbench Full Report + Source Code
StudentsAssistants.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.assistant;
20 
21 import java.util.Collections;
22 import java.util.List;
23 import org.turro.action.Contacts;
24 import org.turro.annotation.ExternalAssistant;
25 import org.turro.entities.Entities;
26 import org.turro.participation.ParticipationReason;
27 import org.turro.plugin.contacts.IContact;
28 import org.turro.students.entities.Challenge;
29 import org.turro.students.entities.PracticalWork;
30 import org.turro.students.entities.Response;
31 
36 @ExternalAssistant
37 public class StudentsAssistants implements IAssistant {
38 
39  @Override
40  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
41  if(entity instanceof String) {
42  addFromEntityPath((String) entity, deep, assistants, data);
43  } else {
44  addFromEntity(entity, deep, assistants, data);
45  }
46  }
47 
48  @Override
49  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
50  Object entity = Entities.getController(entityPath).getEntity();
51  addFromEntity(entity, deep, assistants, data);
52  }
53 
54  @Override
55  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
56  if(entity instanceof Challenge) {
57  Challenge challenge = (Challenge) entity;
58  assistants.addSubject(challenge.getQuestion());
59  assistants.add(new Assistant(challenge.getContact(), challenge));
60  if(deep) {
61  for(Response response : challenge.getResponses()) {
62  for(IContact c : response.getStudentList()) {
63  if(c != null && c.isWebUser()) {
64  assistants.add(new Assistant(c, response));
65  }
66  }
67  }
68  }
69  } else if(entity instanceof Response) {
70  Response response = (Response) entity;
71  Challenge challenge = response.getChallenge();
72  assistants.addSubject(challenge.getQuestion());
73  assistants.add(new Assistant(challenge.getContact(), challenge));
74  for(IContact c : response.getStudentList()) {
75  if(c != null && c.isWebUser()) {
76  assistants.add(new Assistant(c, response));
77  }
78  }
79  if(deep) {
80  }
81  } else if(entity instanceof PracticalWork) {
82  PracticalWork practicalWork = (PracticalWork) entity;
83  assistants.addSubject(practicalWork.getTitle());
84  assistants.add(new Assistant(practicalWork.getIResponsible(), practicalWork));
85  if(deep) {
86  }
87  }
88  }
89 
90  @Override
91  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
92  if((data instanceof String) && ((String) data).contains(AssistantConstants.FROM_STUDENTS)) {
94  .stream().forEach(p -> {
95  IContact c = Contacts.getContact(p.getParticipator().getEntity());
96  if(c != null && c.isWebUser() && c.isStudent()) {
97  assistants.add(new Assistant(c, p.getEntity().getEntity()));
98  }
99  });
100  }
101  }
102 
103  @Override
104  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
105  if((data instanceof String) && ((String) data).contains(AssistantConstants.FROM_STUDENTS)) {
106  String entityPath = Entities.getController(entity).getPath();
107  addFromEntityPathData(entityPath, assistants, data);
108  }
109  }
110 
111  @Override
112  public List<String> getParticiped(IContact contact) {
113  return Collections.EMPTY_LIST;
114  }
115 
116 }
117 
static IContact getContact(Object object)
Definition: Contacts.java:109
List< IEntityParticipation > getParticipations()
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
List< String > getParticiped(IContact contact)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
static IElephantEntity getController(String path)
Definition: Entities.java:78