Unverified Commit a93367b3 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by GitHub
Browse files

Issue on updating membershipForm table and getting organization...#160 (#184)

Remove extra entries for deletion cascade that broke update. Add extra
lines into DELETE call to manually take care of extra entries.
parent 5cb64ace
......@@ -11,20 +11,14 @@
*/
package org.eclipsefoundation.react.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.json.bind.annotation.JsonbTransient;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.ws.rs.core.MultivaluedMap;
......@@ -58,15 +52,6 @@ public class MembershipForm extends BareNode implements TargetedClone<Membership
private Long dateCreated;
private FormState state;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "form_id")
private List<Contact> contacts;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "form_id")
private List<FormWorkingGroup> workingGroups;
@OneToOne(mappedBy = "form", orphanRemoval = true)
private FormOrganization organization;
/** @return the id */
@Override
public String getId() {
......@@ -151,30 +136,6 @@ public class MembershipForm extends BareNode implements TargetedClone<Membership
this.state = state;
}
/**
* @return the contacts
*/
@JsonbTransient
public List<Contact> getContacts() {
return new ArrayList<>(contacts);
}
/**
* @return the workingGroups
*/
@JsonbTransient
public List<FormWorkingGroup> getWorkingGroups() {
return new ArrayList<>(workingGroups);
}
/**
* @return the organization
*/
@JsonbTransient
public FormOrganization getOrganization() {
return organization;
}
@Override
public MembershipForm cloneTo(MembershipForm target) {
target.setUserID(getUserID());
......
......@@ -78,11 +78,14 @@ public class FormOrganizationsResource extends AbstractRESTResource {
if (r != null) {
return r;
}
MembershipForm form = dao.getReference(formID, MembershipForm.class);
// handle cases where an organization already exists and replace it
if (form.getOrganization() != null) {
return update(formID, form.getOrganization().getId(), org);
// check if an org for this form already exists. If so, replace it with this one
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.add(MembershipFormAPIParameterNames.FORM_ID.getName(), formID);
List<FormOrganization> results = dao.get(new RDBMSQuery<>(wrap, filters.get(FormOrganization.class), params));
if (results != null && !results.isEmpty()) {
return update(formID, results.get(0).getId(), org);
} else {
MembershipForm form = dao.getReference(formID, MembershipForm.class);
org.setForm(form);
if (org.getAddress() != null) {
org.getAddress().setOrganization(org);
......
......@@ -14,6 +14,7 @@ package org.eclipsefoundation.react.request;
import java.util.Arrays;
import java.util.List;
import javax.persistence.NoResultException;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
......@@ -136,9 +137,16 @@ public class MembershipFormResource extends AbstractRESTResource {
if (r != null) {
return r;
}
// standard form params
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.add(DefaultUrlParameterNames.ID.getName(), formID);
// FK dependents params
MultivaluedMap<String, String> depParams = new MultivaluedMapImpl<>();
depParams.add(MembershipFormAPIParameterNames.FORM_ID.getName(), formID);
dao.delete(new RDBMSQuery<>(wrap, filters.get(FormWorkingGroup.class), depParams));
dao.delete(new RDBMSQuery<>(wrap, filters.get(Contact.class), depParams));
dao.delete(new RDBMSQuery<>(wrap, filters.get(FormOrganization.class), depParams));
dao.delete(new RDBMSQuery<>(wrap, filters.get(MembershipForm.class), params));
return Response.ok().build();
}
......
......@@ -6,8 +6,6 @@ quarkus.http.cors.exposed-headers=x-csrf-token
quarkus.http.cors.headers=x-csrf-token
## EXTERNAL API CLIENT CONFIG
fdn-accounts/mp-rest/url=https://api.eclipse.org
fdn-accounts/mp-rest/scope=javax.inject.Singleton
fdn-api/mp-rest/url=https://api.eclipse.org/public
fdn-api/mp-rest/scope=javax.inject.Singleton
......@@ -26,7 +24,7 @@ quarkus.mailer.ssl=true
quarkus.datasource.db-kind=mariadb
quarkus.datasource.jdbc.min-size = 5
quarkus.datasource.jdbc.max-size = 15
eclipse.db.default.limit=25
eclipse.db.default.limit=10
eclipse.db.default.limit.max=100
## APP Settings
......@@ -43,23 +41,17 @@ quarkus.oidc.authentication.redirect-path=/api/login
quarkus.oidc.logout.post-logout-path=/
quarkus.oidc.logout.path=/api/logout
security.csrf.enabled=true
quarkus.oidc-client.auth-server-url=https://accounts.eclipse.org/oauth2/
quarkus.oidc-client.discovery-enabled=false
quarkus.oidc-client.token-path=/token
quarkus.oidc-client.grant-options.client.scope=eclipsefdn_view_all_profiles
## Recreate DB profile (easy to trigger in remote envs)
%dbfresh.quarkus.hibernate-orm.database.generation=drop-and-create
## DEV SETTINGS
%dev.quarkus.http.port=8090
%dev.security.csrf.enabled = false
%dev.quarkus.http.cors.origins=https://membership.eclipse.org,https://membership-staging.eclipse.org,http://localhost:8091,http://api.rem.docker,https://www.rem.docker
%dev.eclipse.dataloader.user-ids=malowe, cguindon, epoirier, zhoufang
%dev.eclipse.app.base-url=http://localhost:8090/
%dev.eclipse.mailer.membership.inbox=martin.lowe@eclipse-foundation.org
## Optional dev settings
#%dev.quarkus.hibernate-orm.database.generation=drop-and-create
#%dev.eclipse.dataloader.enabled=true
#%dev.quarkus.mailer.mock=false
#%dev.quarkus.log.category."org.eclipsefoundation".level=DEBUG
\ No newline at end of file
%dev.eclipse.dataloader.form-count=1000
%dev.eclipse.dataloader.user-ids=malowe, cguindon, epoirier, zhoufang
%dev.eclipse.app.base-url=http://localhost:8090/
%dev.quarkus.log.category."org.eclipsefoundation".level=DEBUG
DROP TABLE IF EXISTS Address, FormWorkingGroup, Contact, FormOrganization, MembershipForm CASCADE;
CREATE TABLE `MembershipForm` (
`id` varchar(255) NOT NULL,
`dateCreated` bigint(20) DEFAULT NULL,
`membershipLevel` varchar(255) DEFAULT NULL,
`purchaseOrderRequired` varchar(255) DEFAULT NULL,
`registrationCountry` varchar(255) DEFAULT NULL,
`signingAuthority` bit(1) NOT NULL,
`userID` varchar(255) DEFAULT NULL,
`vatNumber` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Contact` (
`id` varchar(255) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`fName` varchar(255) DEFAULT NULL,
`lName` varchar(255) DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
`type` varchar(255) DEFAULT NULL,
`form_id` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK2g2hji3xsvakv5blqilnol5ad` (`form_id`),
CONSTRAINT `FK2g2hji3xsvakv5blqilnol5ad` FOREIGN KEY (`form_id`) REFERENCES `MembershipForm` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `FormOrganization` (
`id` varchar(255) NOT NULL,
`legalName` varchar(255) DEFAULT NULL,
`twitterHandle` varchar(255) DEFAULT NULL,
`form_id` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_27vg3uhbmy3ev7ote4fjd4evl` (`form_id`),
CONSTRAINT `FKib65ho89l5rvfgqql7wq15oxv` FOREIGN KEY (`form_id`) REFERENCES `MembershipForm` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `FormWorkingGroup` (
`id` varchar(255) NOT NULL,
`effectiveDate` datetime(6) DEFAULT NULL,
`participationLevel` varchar(255) DEFAULT NULL,
`workingGroupID` varchar(255) DEFAULT NULL,
`contact_id` varchar(255) DEFAULT NULL,
`form_id` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_1gt3qh8yu1jpky54o38igvfrq` (`contact_id`),
UNIQUE KEY `UK_2qrha8ti59jcxnvi2h8b9d2u8` (`form_id`),
CONSTRAINT `FK8mhoi37sufequy7nnn19811rv` FOREIGN KEY (`form_id`) REFERENCES `MembershipForm` (`id`),
CONSTRAINT `FKmnoygtwlsvh31vb4volo8odct` FOREIGN KEY (`contact_id`) REFERENCES `Contact` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Address` (
`id` varchar(255) NOT NULL,
`city` varchar(255) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL,
`postalCode` varchar(255) DEFAULT NULL,
`provinceState` varchar(255) DEFAULT NULL,
`street` varchar(255) DEFAULT NULL,
`organization_id` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_i4vgutrsl3ve37hc8xx7vvslf` (`organization_id`),
CONSTRAINT `FKok1ylu26qjwvmfwgxlllbkj8l` FOREIGN KEY (`organization_id`) REFERENCES `FormOrganization` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
\ No newline at end of file
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