use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition in project uPortal by Jasig.
the class PagsRESTController method updatePagsGroup.
@RequestMapping(value = "/v4-3/pags/{pagsGroupName}.json", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
@ResponseBody
public String updatePagsGroup(HttpServletRequest req, HttpServletResponse res, @PathVariable("pagsGroupName") String pagsGroupName, @RequestBody String json) {
res.setContentType(MediaType.APPLICATION_JSON_VALUE);
/*
* This step is necessary; the incoming URLs will sometimes have '+'
* characters for spaces, and the @PathVariable magic doesn't convert them.
*/
String name;
try {
name = URLDecoder.decode(pagsGroupName, "UTF-8");
} catch (UnsupportedEncodingException e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': '" + e.toString() + "' }";
}
IPersonAttributesGroupDefinition inpt;
try {
inpt = objectMapper.readValue(json, PersonAttributesGroupDefinitionImpl.class);
} catch (Exception e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
// should be escaped
return "{ 'error': '" + e.toString() + "' }";
}
if (inpt == null) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "{ 'error': 'Not found' }";
}
if (!name.equals(inpt.getName())) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': 'Group name in URL parameter must match name in JSON payload' }";
}
IPerson person = personManager.getPerson(req);
IPersonAttributesGroupDefinition rslt;
try {
IPersonAttributesGroupDefinition currentDef = pagsService.getPagsDefinitionByName(person, name);
if (currentDef == null) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "{ 'error': 'Not found' }";
}
/*
* Copy over the information being passed in to the JPA-managed
* instance; the following do not support updates (currently):
* - Name
* - Members
*/
currentDef.setDescription(inpt.getDescription());
// little purpose and could be removed.
for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
// NOTE: The deserializer handles testDef --> testGroupDef
testGroupDef.setGroup(currentDef);
}
currentDef.setTestGroups(inpt.getTestGroups());
rslt = pagsService.updatePagsDefinition(person, currentDef);
} catch (IllegalArgumentException iae) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
// should be escaped
return "{ 'error': '" + iae.getMessage() + "' }";
} catch (RuntimeAuthorizationException rae) {
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
return "{ 'error': 'not authorized' }";
} catch (Exception e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': '" + e.toString() + "' }";
}
return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_ACCEPTED);
}
use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition in project uPortal by Jasig.
the class PersonAttributesGroupDefinitionImpl method toElement.
@Override
public void toElement(org.dom4j.Element parent) {
if (parent == null) {
String msg = "Argument 'parent' cannot be null.";
throw new IllegalArgumentException(msg);
}
parent.addElement("name").addText(this.getName());
parent.addElement("description").addText(this.getDescription());
if (!members.isEmpty()) {
org.dom4j.Element elementMembers = DocumentHelper.createElement(new QName("members"));
for (IPersonAttributesGroupDefinition member : members) {
elementMembers.addElement("member-name").addText(member.getName());
}
parent.add(elementMembers);
}
if (!testGroups.isEmpty()) {
org.dom4j.Element elementSelectionTest = DocumentHelper.createElement(new QName("selection-test"));
for (IPersonAttributesGroupTestGroupDefinition testGroup : testGroups) {
testGroup.toElement(elementSelectionTest);
}
parent.add(elementSelectionTest);
}
}
use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition in project uPortal by Jasig.
the class PagsRESTController method createPagsGroup.
@RequestMapping(value = "/v4-3/pags/{parentGroupName}.json", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public String createPagsGroup(HttpServletRequest request, HttpServletResponse res, @PathVariable("parentGroupName") String parentGroupName, @RequestBody String json) {
res.setContentType(MediaType.APPLICATION_JSON_VALUE);
/*
* This step is necessary; the incoming URLs will sometimes have '+'
* characters for spaces, and the @PathVariable magic doesn't convert them.
*/
String name;
try {
name = URLDecoder.decode(parentGroupName, "UTF-8");
} catch (UnsupportedEncodingException e) {
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return "{ 'error': '" + e.getMessage() + "' }";
}
IPersonAttributesGroupDefinition inpt;
try {
inpt = objectMapper.readValue(json, PersonAttributesGroupDefinitionImpl.class);
} catch (Exception e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
// should be escaped
return "{ 'error': '" + e.getMessage() + "' }";
}
// Obtain a real reference to the parent group
EntityIdentifier[] eids = GroupService.searchForGroups(name, IGroupConstants.IS, IPerson.class);
if (eids.length == 0) {
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return "{ 'error': 'Parent group does not exist: " + name + "' }";
}
IEntityGroup parentGroup = // Names must be unique
(IEntityGroup) GroupService.getGroupMember(eids[0]);
IPerson person = personManager.getPerson(request);
IPersonAttributesGroupDefinition rslt;
try {
// A little weird that we need to do both;
// need some PAGS DAO/Service refactoring
rslt = pagsService.createPagsDefinition(person, parentGroup, inpt.getName(), inpt.getDescription());
// little purpose and could be removed.
for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
// NOTE: The deserializer handles testDef --> testGroupDef
testGroupDef.setGroup(rslt);
}
rslt.setTestGroups(inpt.getTestGroups());
rslt.setMembers(inpt.getMembers());
pagsService.updatePagsDefinition(person, rslt);
} catch (RuntimeAuthorizationException rae) {
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
return "{ 'error': 'not authorized' }";
} catch (IllegalArgumentException iae) {
res.setStatus(HttpServletResponse.SC_CONFLICT);
return "{ 'error': '" + iae.getMessage() + "' }";
} catch (Exception e) {
e.printStackTrace();
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': '" + e.getMessage() + "' }";
}
return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_CREATED);
}
use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition in project uPortal by Jasig.
the class PersonAttributesGroupImportHelper method dropTestGroupsAndTests.
public void dropTestGroupsAndTests(String groupName) {
Set<IPersonAttributesGroupDefinition> groups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(groupName);
IPersonAttributesGroupDefinition group = groups.iterator().next();
Set<IPersonAttributesGroupTestGroupDefinition> testGroups = group.getTestGroups();
// Disconnect the test groups
group.setTestGroups(new HashSet<IPersonAttributesGroupTestGroupDefinition>());
personAttributesGroupDefinitionDao.updatePersonAttributesGroupDefinition(group);
// Cascade the test group delete to the tests
for (IPersonAttributesGroupTestGroupDefinition testGroup : testGroups) {
personAttributesGroupTestGroupDefinitionDao.deletePersonAttributesGroupTestGroupDefinition(testGroup);
}
}
use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition in project uPortal by Jasig.
the class JpaPersonAttributesGroupTestGroupDefinitionDao method createPersonAttributesGroupTestGroupDefinition.
@PortalTransactional
@Override
public IPersonAttributesGroupTestGroupDefinition createPersonAttributesGroupTestGroupDefinition(IPersonAttributesGroupDefinition group) {
final IPersonAttributesGroupTestGroupDefinition personAttributesGroupTestGroupDefinition = new PersonAttributesGroupTestGroupDefinitionImpl((PersonAttributesGroupDefinitionImpl) group);
this.getEntityManager().persist(personAttributesGroupTestGroupDefinition);
return personAttributesGroupTestGroupDefinition;
}
Aggregations