Revision 56746
Added by Michele Artini over 4 years ago
OrganizationController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.organizations.controller; |
2 | 2 |
|
3 |
import java.util.Arrays; |
|
3 | 4 |
import java.util.List; |
4 | 5 |
import java.util.UUID; |
5 | 6 |
|
... | ... | |
15 | 16 |
import org.springframework.web.bind.annotation.RequestParam; |
16 | 17 |
import org.springframework.web.bind.annotation.RestController; |
17 | 18 |
|
19 |
import eu.dnetlib.organizations.model.Acronym; |
|
18 | 20 |
import eu.dnetlib.organizations.model.OpenaireSimRel; |
21 |
import eu.dnetlib.organizations.model.Organization; |
|
22 |
import eu.dnetlib.organizations.model.OtherIdentifier; |
|
23 |
import eu.dnetlib.organizations.model.OtherName; |
|
24 |
import eu.dnetlib.organizations.model.Type; |
|
25 |
import eu.dnetlib.organizations.model.Url; |
|
19 | 26 |
import eu.dnetlib.organizations.model.utils.BrowseEntry; |
20 | 27 |
import eu.dnetlib.organizations.model.utils.RelationByOrg; |
21 | 28 |
import eu.dnetlib.organizations.model.view.OrganizationSimpleView; |
22 | 29 |
import eu.dnetlib.organizations.model.view.OrganizationView; |
30 |
import eu.dnetlib.organizations.repository.AcronymRepository; |
|
23 | 31 |
import eu.dnetlib.organizations.repository.OpenaireSimRelRepository; |
32 |
import eu.dnetlib.organizations.repository.OrganizationRepository; |
|
33 |
import eu.dnetlib.organizations.repository.OtherIdentifierRepository; |
|
34 |
import eu.dnetlib.organizations.repository.OtherNameRepository; |
|
35 |
import eu.dnetlib.organizations.repository.TypeRepository; |
|
36 |
import eu.dnetlib.organizations.repository.UrlRepository; |
|
24 | 37 |
import eu.dnetlib.organizations.repository.readonly.OrganizationSimpleViewRepository; |
25 | 38 |
import eu.dnetlib.organizations.repository.readonly.OrganizationViewRepository; |
26 | 39 |
|
... | ... | |
35 | 48 |
@Autowired |
36 | 49 |
private OpenaireSimRelRepository openaireSimRelRepository; |
37 | 50 |
|
38 |
@RequestMapping(value = "/get", method = RequestMethod.GET) |
|
39 |
public OrganizationView findById(@RequestParam final String id) { |
|
40 |
return organizationViewRepository.findById(id).get(); |
|
41 |
} |
|
51 |
@Autowired |
|
52 |
private AcronymRepository acronymRepository; |
|
53 |
@Autowired |
|
54 |
private OrganizationRepository organizationRepository; |
|
55 |
@Autowired |
|
56 |
private OtherIdentifierRepository otherIdentifierRepository; |
|
57 |
@Autowired |
|
58 |
private OtherNameRepository otherNameRepository; |
|
59 |
@Autowired |
|
60 |
private TypeRepository typeRepository; |
|
61 |
@Autowired |
|
62 |
private UrlRepository urlRepository; |
|
42 | 63 |
|
43 | 64 |
@RequestMapping(value = "/save", method = RequestMethod.POST) |
44 |
public OrganizationView save(@RequestBody final OrganizationView org) { |
|
65 |
public List<String> save(@RequestBody final OrganizationView org) { |
|
66 |
final String orgId = insertOrUpdateOrganization(org, StringUtils.isNotBlank(org.getId())); |
|
67 |
return Arrays.asList(orgId); |
|
68 |
} |
|
45 | 69 |
|
46 |
final String id; |
|
47 |
if (StringUtils.isNotBlank(org.getId())) { |
|
48 |
// UPDATE |
|
70 |
private String insertOrUpdateOrganization(final OrganizationView org, final boolean update) { |
|
49 | 71 |
|
50 |
id = org.getId(); |
|
51 |
} else { |
|
52 |
// INSERT |
|
72 |
final String orgId = update ? org.getId() : "openorgs____::" + DigestUtils.md5Hex(UUID.randomUUID().toString()); |
|
53 | 73 |
|
54 |
id = "openorgs____::" + DigestUtils.md5Hex(UUID.randomUUID().toString()); |
|
74 |
if (update) { |
|
75 |
acronymRepository.deleteByOrgId(orgId); |
|
76 |
otherNameRepository.deleteByOrgId(orgId); |
|
77 |
otherIdentifierRepository.deleteByOrgId(orgId); |
|
78 |
typeRepository.deleteByOrgId(orgId); |
|
79 |
urlRepository.deleteByOrgId(orgId); |
|
55 | 80 |
} |
56 | 81 |
|
82 |
organizationRepository.save(new Organization(orgId, org.getName(), org.getLat(), org.getLng(), org.getCity(), org.getCountry())); |
|
83 |
org.getAcronyms().forEach(s -> acronymRepository.save(new Acronym(orgId, s))); |
|
84 |
org.getOtherNames().forEach(n -> otherNameRepository.save(new OtherName(orgId, n.getName(), n.getLang()))); |
|
85 |
org.getOtherIdentifiers().forEach(id -> otherIdentifierRepository.save(new OtherIdentifier(orgId, id.getId(), id.getType()))); |
|
86 |
org.getTypes().forEach(t -> typeRepository.save(new Type(orgId, t))); |
|
87 |
org.getUrls().forEach(u -> urlRepository.save(new Url(orgId, u))); |
|
88 |
|
|
89 |
if (update) { |
|
90 |
// SET LAST MODIFICATION DATE AND USER |
|
91 |
} else { |
|
92 |
// SET LAST CREATION AND MODIFICATION 5DATE AND USER |
|
93 |
} |
|
94 |
|
|
95 |
return orgId; |
|
96 |
} |
|
97 |
|
|
98 |
@RequestMapping(value = "/get", method = RequestMethod.GET) |
|
99 |
public OrganizationView findById(@RequestParam final String id) { |
|
57 | 100 |
return organizationViewRepository.findById(id).get(); |
58 | 101 |
} |
59 | 102 |
|
Also available in: Unified diff