Commit 8940d8b5 authored by Martin Lowe's avatar Martin Lowe 🇨🇦
Browse files

Merge branch 'malowe/dev/433' into 'dev'

#433 - Fix issues regarding missing org info entry

See merge request !449
parents 7bc58f7d daa699e5
Pipeline #1557 passed with stage
in 0 seconds
......@@ -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()) {
......
......@@ -39,10 +39,12 @@ import javax.imageio.stream.ImageOutputStream;
import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.core.namespace.DefaultUrlParameterNames;
import org.eclipsefoundation.eclipsedb.dao.EclipseDBPersistenceDAO;
import org.eclipsefoundation.eclipsedb.dto.OrganizationInformation;
import org.eclipsefoundation.persistence.model.RDBMSQuery;
......@@ -50,6 +52,7 @@ import org.eclipsefoundation.persistence.service.FilterService;
import org.eclipsefoundation.react.helper.ImageFileHelper;
import org.eclipsefoundation.react.namespace.ImageStoreFormat;
import org.eclipsefoundation.react.service.ImageStoreService;
import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -159,15 +162,26 @@ public class DefaultImageStoreService implements ImageStoreService {
if (config.persistToDb() && format.isPresent()
&& ImageStoreFormat.ImageStoreFormats.WEB.equals(format.get()) && StringUtils.isNumeric(fileName)) {
// get a ref to the given organization information object
OrganizationInformation oi = dao.getReference(Integer.valueOf(fileName), OrganizationInformation.class);
// as long as this org exists, update the logo
if (oi != null) {
oi.setLargeLogo(bytes);
oi.setSmallLogo(bytes);
oi.setLargeMime(mimeType);
oi.setSmallMime(mimeType);
dao.add(new RDBMSQuery<>(new RequestWrapper(), filters.get(OrganizationInformation.class)), Arrays.asList(oi));
// get ref and update the object
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.add(DefaultUrlParameterNames.ID.getName(), fileName);
List<OrganizationInformation> infoRefs = dao
.get(new RDBMSQuery<>(new RequestWrapper(), filters.get(OrganizationInformation.class), params));
// if ref doesn't exist, create one
OrganizationInformation oi;
if (infoRefs.isEmpty()) {
oi = new OrganizationInformation();
oi.setOrganizationID(Integer.valueOf(fileName));
oi.setCompanyUrl("");
} else {
oi = infoRefs.get(0);
}
oi.setLargeLogo(bytes);
oi.setSmallLogo(bytes);
oi.setLargeMime(mimeType);
oi.setSmallMime(mimeType);
dao.add(new RDBMSQuery<>(new RequestWrapper(), filters.get(OrganizationInformation.class)), Arrays.asList(oi));
}
// write will create and overwrite file by default if it exists
......
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