updated whitelist service and repository
parent
6a180acf3c
commit
8ae1b376fe
|
@ -67,14 +67,6 @@ public interface WhitelistedSiteRepository {
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
@ -83,4 +75,12 @@ public interface WhitelistedSiteRepository {
|
|||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Removes an WhitelistedSite from the repository
|
||||
*
|
||||
* @param id
|
||||
* the id of the WhitelistedSite to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Persists a WhitelistedSite
|
||||
* Persists a new WhitelistedSite
|
||||
*
|
||||
* @param whitelistedSite
|
||||
* the WhitelistedSite to be saved
|
||||
* @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
|
||||
@Transactional
|
||||
public Collection<WhitelistedSite> getAll() {
|
||||
TypedQuery<WhitelistedSite> query = manager.createNamedQuery(
|
||||
"WhitelistedSite.getAll", WhitelistedSite.class);
|
||||
TypedQuery<WhitelistedSite> query = manager.createNamedQuery("WhitelistedSite.getAll", WhitelistedSite.class);
|
||||
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
|
||||
@Transactional
|
||||
public WhitelistedSite save(WhitelistedSite whiteListedSite) {
|
||||
return saveOrUpdate(whiteListedSite.getId(), manager, whiteListedSite);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite) {
|
||||
return saveOrUpdate(oldWhitelistedSite.getId(), manager, whitelistedSite);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public WhitelistedSite getByClientId(String clientId) {
|
||||
|
|
|
@ -64,15 +64,10 @@ public class WhitelistedSiteServiceImpl implements WhitelistedSiteService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeById(Long id) {
|
||||
WhitelistedSite w = repository.getById(id);
|
||||
if (w != null) {
|
||||
repository.remove(w);
|
||||
public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) {
|
||||
if (whitelistedSite.getId() != null) {
|
||||
throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhitelistedSite save(WhitelistedSite whitelistedSite) {
|
||||
return repository.save(whitelistedSite);
|
||||
}
|
||||
|
||||
|
@ -91,4 +86,12 @@ public class WhitelistedSiteServiceImpl implements WhitelistedSiteService {
|
|||
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
|
||||
whitelist.setCreatorUserId(p.getName());
|
||||
|
||||
WhitelistedSite newWhitelist = whitelistService.save(whitelist);
|
||||
WhitelistedSite newWhitelist = whitelistService.saveNew(whitelist);
|
||||
|
||||
m.put("entity", newWhitelist);
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class WhitelistApi {
|
|||
// TODO: throw new "entity not found"
|
||||
}
|
||||
|
||||
WhitelistedSite newWhitelist = whitelistService.save(whitelist);
|
||||
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
|
||||
|
||||
m.put("entity", newWhitelist);
|
||||
|
||||
|
|
Loading…
Reference in New Issue