001package systems.dmx.contacts; 002 003import systems.dmx.core.RelatedTopic; 004import systems.dmx.core.model.AssociationModel; 005import systems.dmx.core.osgi.PluginActivator; 006import systems.dmx.core.service.event.PreCreateAssociationListener; 007import systems.dmx.core.util.DMXUtils; 008 009import javax.ws.rs.GET; 010import javax.ws.rs.Path; 011import javax.ws.rs.PathParam; 012import javax.ws.rs.Produces; 013 014import java.util.List; 015 016 017 018@Path("/contact") 019@Produces("application/json") 020public class ContactsPlugin extends PluginActivator implements ContactsService, PreCreateAssociationListener { 021 022 // -------------------------------------------------------------------------------------------------- Public Methods 023 024 025 026 // ************************************** 027 // *** ContactsService Implementation *** 028 // ************************************** 029 030 031 032 @GET 033 @Path("/{id}/institutions") 034 @Override 035 public List<RelatedTopic> getInstitutions(@PathParam("id") long personId) { 036 return dmx.getTopic(personId).getRelatedTopics("dmx.contacts.organization_association", "dmx.core.default", 037 "dmx.core.default", "dmx.contacts.institution"); 038 } 039 040 @GET 041 @Path("/{id}/persons") 042 @Override 043 public List<RelatedTopic> getPersons(@PathParam("id") long instId) { 044 return dmx.getTopic(instId).getRelatedTopics("dmx.contacts.organization_association", "dmx.core.default", 045 "dmx.core.default", "dmx.contacts.person"); 046 } 047 048 049 050 // ******************************** 051 // *** Listener Implementations *** 052 // ******************************** 053 054 055 056 @Override 057 public void preCreateAssociation(AssociationModel assoc) { 058 // Person <-> Institution 059 DMXUtils.associationAutoTyping(assoc, "dmx.contacts.person", "dmx.contacts.institution", 060 "dmx.contacts.organization_association", "dmx.core.default", "dmx.core.default", dmx); 061 } 062}