Skip to content

Commit

Permalink
avniproject/avni-webapp#1147 - organisation category support
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Apr 10, 2024
1 parent 6d85fb2 commit 8e384fa
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.avni.server.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.avni.server.domain.metadata.OrganisationCategory;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.UUID;

@Entity
@Table(name = "organisation")
Expand All @@ -24,6 +24,10 @@ public class Organisation extends ETLEntity {
@JoinColumn(name = "account_id", nullable = false)
private Account account;

@NotNull
@Enumerated(EnumType.STRING)
private OrganisationCategory category;

public Organisation() {
}

Expand Down Expand Up @@ -76,4 +80,12 @@ public boolean isNew() {
public String getEffectiveUsernameSuffix() {
return usernameSuffix == null ? getDbUser() : usernameSuffix;
}

public OrganisationCategory getCategory() {
return category;
}

public void setCategory(OrganisationCategory organisationCategory) {
this.category = organisationCategory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.avni.server.domain.metadata;

public enum OrganisationCategory {
Production, UAT, Prototype, Temporary
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public ResponseEntity save(@RequestBody OrganisationContract request) {
org.setUuid(request.getUuid() == null ? UUID.randomUUID().toString() : request.getUuid());
org.setDbUser(request.getDbUser());
org.setSchemaName(request.getSchemaName());
org.setCategory(request.getCategory());
setAttributesOnOrganisation(request, org);
setOrgAccountByIdOrDefault(org, request.getAccountId());

Expand Down Expand Up @@ -161,6 +162,7 @@ private void setAttributesOnOrganisation(@RequestBody OrganisationContract reque
}
organisation.setMediaDirectory(request.getMediaDirectory());
organisation.setVoided(request.isVoided());
organisation.setCategory(request.getCategory());
}

private void setOrgAccountByIdOrDefault(Organisation organisation, Long accountId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.avni.server.web.request;

import org.avni.server.domain.Organisation;
import org.avni.server.domain.metadata.OrganisationCategory;

public class OrganisationContract extends ETLContract {
private Long parentOrganisationId;
private String mediaDirectory;
private String usernameSuffix;
private Long accountId;
private OrganisationCategory category;

public static OrganisationContract fromEntity(Organisation organisation) {
OrganisationContract organisationContract = new OrganisationContract();
Expand All @@ -16,6 +18,7 @@ public static OrganisationContract fromEntity(Organisation organisation) {
organisationContract.setMediaDirectory(organisation.getMediaDirectory());
organisationContract.setUsernameSuffix(organisation.getEffectiveUsernameSuffix());
organisationContract.setAccountId(organisation.getAccount() == null ? null : organisation.getAccount().getId());
organisationContract.setCategory(organisation.getCategory());
mapEntity(organisationContract, organisation);
return organisationContract;
}
Expand Down Expand Up @@ -52,4 +55,11 @@ public void setMediaDirectory(String mediaDirectory) {
this.mediaDirectory = mediaDirectory;
}

public OrganisationCategory getCategory() {
return category;
}

public void setCategory(OrganisationCategory category) {
this.category = category;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.avni.server.web.request;

import org.avni.server.domain.JsonObject;
import org.avni.server.domain.metadata.OrganisationCategory;
import org.springframework.hateoas.core.Relation;

import java.util.List;
Expand All @@ -9,15 +10,13 @@
public class UserInfoClientContract extends UserInfoContract {
private long lastSessionTime;
private List<GroupPrivilegeContract> privileges;
private String[] roles;

public UserInfoClientContract() {
}

public UserInfoClientContract(String username, String orgName, Long orgId, String usernameSuffix, String[] roles, JsonObject settings, String name, String catchmentName, JsonObject syncSettings, List<GroupPrivilegeContract> privileges) {
super(username, orgName, orgId, usernameSuffix, settings, name, catchmentName, syncSettings);
this.privileges = privileges;
this.roles = roles;
}

public List<GroupPrivilegeContract> getPrivileges() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table organisation add column category varchar(255) not null default 'Production';
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.avni.server.domain.Account;
import org.avni.server.domain.Organisation;
import org.avni.server.domain.metadata.OrganisationCategory;

import java.util.UUID;

Expand All @@ -10,7 +11,7 @@ public class TestOrganisationBuilder {

public TestOrganisationBuilder withMandatoryFields() {
String placeholder = UUID.randomUUID().toString();
return withUuid(placeholder).withDbUser("testDbUser").withName(placeholder).withSchemaName(placeholder);
return withUuid(placeholder).withDbUser("testDbUser").withName(placeholder).withSchemaName(placeholder).setCategory(OrganisationCategory.Production);
}

public TestOrganisationBuilder setId(long id) {
Expand Down Expand Up @@ -43,6 +44,11 @@ public TestOrganisationBuilder withAccount(Account account) {
return this;
}

public TestOrganisationBuilder setCategory(OrganisationCategory organisationCategory) {
organisation.setCategory(organisationCategory);
return this;
}

public Organisation build() {
return organisation;
}
Expand Down

0 comments on commit 8e384fa

Please sign in to comment.