updated whitelist service and repository
parent
6a180acf3c
commit
8ae1b376fe
|
@ -67,14 +67,6 @@ public interface WhitelistedSiteRepository {
|
||||||
*/
|
*/
|
||||||
public void remove(WhitelistedSite whitelistedSite);
|
public void remove(WhitelistedSite whitelistedSite);
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an WhitelistedSite from the repository
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* the id of the IdToken to remove
|
|
||||||
*/
|
|
||||||
public void removeById(Long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persists a WhitelistedSite
|
* Persists a WhitelistedSite
|
||||||
*
|
*
|
||||||
|
@ -83,4 +75,12 @@ public interface WhitelistedSiteRepository {
|
||||||
*/
|
*/
|
||||||
public WhitelistedSite save(WhitelistedSite whiteListedSite);
|
public WhitelistedSite save(WhitelistedSite whiteListedSite);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persist changes to a whitelistedSite. The ID of oldWhitelistedSite is retained.
|
||||||
|
* @param oldWhitelistedSite
|
||||||
|
* @param whitelistedSite
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,19 +68,17 @@ public interface WhitelistedSiteService {
|
||||||
public void remove(WhitelistedSite whitelistedSite);
|
public void remove(WhitelistedSite whitelistedSite);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an WhitelistedSite from the repository
|
* Persists a new WhitelistedSite
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* the id of the WhitelistedSite to remove
|
|
||||||
*/
|
|
||||||
public void removeById(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Persists a WhitelistedSite
|
|
||||||
*
|
*
|
||||||
* @param whitelistedSite
|
* @param whitelistedSite
|
||||||
* the WhitelistedSite to be saved
|
* the WhitelistedSite to be saved
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public WhitelistedSite save(WhitelistedSite whitelistedSite);
|
public WhitelistedSite saveNew(WhitelistedSite whitelistedSite);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing whitelisted site
|
||||||
|
*/
|
||||||
|
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,7 @@ public class JpaWhitelistedSiteRepository implements WhitelistedSiteRepository {
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Collection<WhitelistedSite> getAll() {
|
public Collection<WhitelistedSite> getAll() {
|
||||||
TypedQuery<WhitelistedSite> query = manager.createNamedQuery(
|
TypedQuery<WhitelistedSite> query = manager.createNamedQuery("WhitelistedSite.getAll", WhitelistedSite.class);
|
||||||
"WhitelistedSite.getAll", WhitelistedSite.class);
|
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,20 +67,18 @@ public class JpaWhitelistedSiteRepository implements WhitelistedSiteRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public void removeById(Long id) {
|
|
||||||
WhitelistedSite found = getById(id);
|
|
||||||
|
|
||||||
manager.remove(found);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public WhitelistedSite save(WhitelistedSite whiteListedSite) {
|
public WhitelistedSite save(WhitelistedSite whiteListedSite) {
|
||||||
return saveOrUpdate(whiteListedSite.getId(), manager, whiteListedSite);
|
return saveOrUpdate(whiteListedSite.getId(), manager, whiteListedSite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite) {
|
||||||
|
return saveOrUpdate(oldWhitelistedSite.getId(), manager, whitelistedSite);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public WhitelistedSite getByClientId(String clientId) {
|
public WhitelistedSite getByClientId(String clientId) {
|
||||||
|
|
|
@ -64,15 +64,10 @@ public class WhitelistedSiteServiceImpl implements WhitelistedSiteService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeById(Long id) {
|
public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) {
|
||||||
WhitelistedSite w = repository.getById(id);
|
if (whitelistedSite.getId() != null) {
|
||||||
if (w != null) {
|
throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId());
|
||||||
repository.remove(w);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WhitelistedSite save(WhitelistedSite whitelistedSite) {
|
|
||||||
return repository.save(whitelistedSite);
|
return repository.save(whitelistedSite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,4 +86,12 @@ public class WhitelistedSiteServiceImpl implements WhitelistedSiteService {
|
||||||
return repository.getByCreator(creatorId);
|
return repository.getByCreator(creatorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite) {
|
||||||
|
if (oldWhitelistedSite == null || whitelistedSite == null) {
|
||||||
|
throw new IllegalArgumentException("Neither the old or new sites may be null");
|
||||||
|
}
|
||||||
|
return repository.update(oldWhitelistedSite, whitelistedSite);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class WhitelistApi {
|
||||||
// save the id of the person who created this
|
// save the id of the person who created this
|
||||||
whitelist.setCreatorUserId(p.getName());
|
whitelist.setCreatorUserId(p.getName());
|
||||||
|
|
||||||
WhitelistedSite newWhitelist = whitelistService.save(whitelist);
|
WhitelistedSite newWhitelist = whitelistService.saveNew(whitelist);
|
||||||
|
|
||||||
m.put("entity", newWhitelist);
|
m.put("entity", newWhitelist);
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public class WhitelistApi {
|
||||||
// TODO: throw new "entity not found"
|
// TODO: throw new "entity not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
WhitelistedSite newWhitelist = whitelistService.save(whitelist);
|
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
|
||||||
|
|
||||||
m.put("entity", newWhitelist);
|
m.put("entity", newWhitelist);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue