Commit 0a2e1315 authored by Martin Lowe's avatar Martin Lowe 🇨🇦
Browse files

Change org info update to create orginfo when missing instead of failing

parent f6f54d41
......@@ -154,18 +154,23 @@ public class OrganizationResource extends AbstractRESTResource {
@Path("{orgID:\\d+}")
public Response update(@PathParam("orgID") String organizationID, OrganizationInfoUpdateRequest updateRequest) {
// get ref and update the object
OrganizationInformation infoRef = eclipseDBDao.getReference(Integer.valueOf(organizationID),
OrganizationInformation.class);
if (infoRef == null) {
return Response.status(404).build();
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.add(DefaultUrlParameterNames.ID.getName(), organizationID);
List<OrganizationInformation> infoRefs = eclipseDBDao
.get(new RDBMSQuery<>(wrap, filters.get(OrganizationInformation.class), params));
// if ref doesn't exist, create one
OrganizationInformation infoRef;
if (infoRefs.isEmpty()) {
infoRef = new OrganizationInformation();
infoRef.setOrganizationID(Integer.valueOf(organizationID));
} else {
infoRef = infoRefs.get(0);
}
infoRef.setCompanyUrl(updateRequest.getCompanyUrl());
infoRef.setShortDescription(updateRequest.getDescription());
infoRef.setLongDescription(updateRequest.getDescription());
// create the param map and update the org info
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.add(DefaultUrlParameterNames.ID.getName(), organizationID);
// update the org info
List<OrganizationInformation> updatedOrg = eclipseDBDao.add(
new RDBMSQuery<>(wrap, filters.get(OrganizationInformation.class), params), Arrays.asList(infoRef));
if (updatedOrg.isEmpty()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment