Commit 61425426 authored by Matija Obreza's avatar Matija Obreza
Browse files

Ensure one primary Partner record

parent a84ee81d
......@@ -31,6 +31,13 @@ import org.springframework.security.access.prepost.PreAuthorize;
*/
public interface PartnerService {
/**
* Gets the primary partner.
*
* @return the primary partner
*/
Partner getPrimaryPartner();
/**
* Method creating Partner.
*
......
......@@ -25,7 +25,9 @@ import org.genesys.common.model.Partner;
import org.genesys.common.persistence.PartnerRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.domain.Page;
......@@ -40,7 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Service
@Transactional(readOnly = true)
public class PartnerServiceImpl implements PartnerService {
public class PartnerServiceImpl implements PartnerService, InitializingBean {
private static final Logger LOG = LoggerFactory.getLogger(PartnerServiceImpl.class);
......@@ -50,6 +52,30 @@ public class PartnerServiceImpl implements PartnerService {
@Autowired
private Utils utils;
@Value("${partner.primary.uuid}")
private UUID primaryPartnerUuid;
private Partner primaryPartner;
@Override
public void afterPropertiesSet() throws Exception {
Partner primaryPartner = loadPartner(primaryPartnerUuid);
if (primaryPartner == null) {
primaryPartner=new Partner();
primaryPartner.setUuid(primaryPartnerUuid);
primaryPartner.setName("Genesys Catalog");
primaryPartner.setShortName("genesys");
primaryPartner = createPartner(primaryPartner);
}
this.primaryPartner = primaryPartner;
}
@Override
public Partner getPrimaryPartner() {
return primaryPartner;
}
/**
* {@inheritDoc}
*/
......@@ -187,4 +213,5 @@ public class PartnerServiceImpl implements PartnerService {
}
return partner;
}
}
......@@ -36,6 +36,9 @@ db.updateSchema=true
#db.pool.initialSize=5
#db.pool.maxActive=10
# Default partner UUID
partner.primary.uuid=a870b3b2-1dfc-459f-abc8-8c10ca8aaab4
file.repository.path=/file_repository
#AWS parameter values
......
......@@ -23,10 +23,12 @@ db.pool.maxActive=10
# WARNING: Make sure liquibase-changeLog.yml contains required changes. Do not rely on db.updateSchema!
db.updateSchema=false
default.admin.email=admin@example.com
default.admin.password=Admin123!
# Default partner UUID
partner.primary.uuid=39d3022b-dfca-45d8-98f1-3eeaa6c3e605
default.oauthclient.clientId=my-trusted-client
default.oauthclient.clientSecret=my-secret-client
......
......@@ -26,6 +26,9 @@ db.pool.maxActive=5
default.admin.email=admin@example.com
default.admin.password=Admin123!
# Default partner UUID
partner.primary.uuid=a870b3b2-1dfc-459f-abc8-8c10ca8aaab4
default.oauthclient.clientId=my-trusted-client
default.oauthclient.clientSecret=my-secret-client
default.oauth.accessToken.validity=21600
......
Supports Markdown
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