use of org.geotoolkit.sml.xml.v100.Identifier in project ORCID-Source by ORCID.
the class WorksTest method testWorksWithPartOfRelationshipDontGetGrouped.
@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
String accessTokenForClient1 = getAccessToken();
String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
Work work1 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work1.setPutCode(null);
work1.setVisibility(Visibility.PUBLIC);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc1.WorkTitle title1 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title1.setTitle(new Title("Work # 1" + time));
work1.setWorkTitle(title1);
WorkExternalIdentifier wExtId1 = new WorkExternalIdentifier();
wExtId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getExternalIdentifier().clear();
work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
Work work2 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work2.setPutCode(null);
work2.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_rc1.WorkTitle title2 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title2.setTitle(new Title("Work # 2" + time));
work2.setWorkTitle(title2);
work2.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId2 = new WorkExternalIdentifier();
wExtId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId2.setRelationship(Relationship.PART_OF);
wExtId2.setUrl(new Url("http://orcid.org/work#2"));
work2.getExternalIdentifiers().getExternalIdentifier().clear();
work2.getExternalIdentifiers().getExternalIdentifier().add(wExtId2);
Work work3 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work3.setPutCode(null);
work3.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_rc1.WorkTitle title3 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title3.setTitle(new Title("Work # 3" + time));
work3.setWorkTitle(title3);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId3 = new WorkExternalIdentifier();
wExtId3.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId3.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId3.setRelationship(Relationship.SELF);
wExtId3.setUrl(new Url("http://orcid.org/work#3"));
work3.getExternalIdentifiers().getExternalIdentifier().clear();
work3.getExternalIdentifiers().getExternalIdentifier().add(wExtId3);
// Add the three works
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode1 = getPutCodeFromResponse(postResponse);
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode2 = getPutCodeFromResponse(postResponse);
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode3 = getPutCodeFromResponse(postResponse);
ClientResponse activitiesResponse = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), accessTokenForClient1);
assertEquals(Response.Status.OK.getStatusCode(), activitiesResponse.getStatus());
ActivitiesSummary activities = activitiesResponse.getEntity(ActivitiesSummary.class);
assertNotNull(activities);
assertFalse(activities.getWorks().getWorkGroup().isEmpty());
WorkGroup work1Group = null;
WorkGroup work2Group = null;
WorkGroup work3Group = null;
boolean work1found = false;
boolean work2found = false;
boolean work3found = false;
for (WorkGroup group : activities.getWorks().getWorkGroup()) {
if (group.getIdentifiers().getIdentifier() == null || group.getIdentifiers().getIdentifier().isEmpty()) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 2" + time).equals(title)) {
work2found = true;
work2Group = group;
}
}
} else {
for (Identifier id : group.getIdentifiers().getIdentifier()) {
// If it is the ID is the one we are looking for
if (id.getExternalIdentifierId().equals("Work Id " + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 1" + time).equals(title)) {
work1found = true;
work1Group = group;
} else if (("Work # 3" + time).equals(title)) {
work3found = true;
work3Group = group;
}
}
}
}
}
}
assertTrue(work1found);
assertTrue(work2found);
assertTrue(work3found);
// Check that work # 1 and Work # 3 are in the same work
assertEquals(work1Group, work3Group);
// Check that work # 2 is not in the same group than group # 1
assertThat(work2Group, not(work1Group));
// Remove all created works
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode3, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.geotoolkit.sml.xml.v100.Identifier in project ORCID-Source by ORCID.
the class MemberV2Test method testWorksWithPartOfRelationshipDontGetGrouped.
@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
String accessTokenForClient1 = getAccessToken();
String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
Work work1 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work1.setPutCode(null);
work1.setVisibility(Visibility.PUBLIC);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc1.WorkTitle title1 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title1.setTitle(new Title("Work # 1" + time));
work1.setWorkTitle(title1);
WorkExternalIdentifier wExtId1 = new WorkExternalIdentifier();
wExtId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getWorkExternalIdentifier().clear();
work1.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId1);
Work work2 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work2.setPutCode(null);
work2.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_rc1.WorkTitle title2 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title2.setTitle(new Title("Work # 2" + time));
work2.setWorkTitle(title2);
work2.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId2 = new WorkExternalIdentifier();
wExtId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId2.setRelationship(Relationship.PART_OF);
wExtId2.setUrl(new Url("http://orcid.org/work#2"));
work2.getExternalIdentifiers().getWorkExternalIdentifier().clear();
work2.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId2);
Work work3 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work3.setPutCode(null);
work3.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_rc1.WorkTitle title3 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title3.setTitle(new Title("Work # 3" + time));
work3.setWorkTitle(title3);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId3 = new WorkExternalIdentifier();
wExtId3.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId3.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId3.setRelationship(Relationship.SELF);
wExtId3.setUrl(new Url("http://orcid.org/work#3"));
work3.getExternalIdentifiers().getWorkExternalIdentifier().clear();
work3.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId3);
// Add the three works
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
ClientResponse activitiesResponse = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), accessTokenForClient1);
assertEquals(Response.Status.OK.getStatusCode(), activitiesResponse.getStatus());
ActivitiesSummary activities = activitiesResponse.getEntity(ActivitiesSummary.class);
assertNotNull(activities);
assertFalse(activities.getWorks().getWorkGroup().isEmpty());
WorkGroup work1Group = null;
WorkGroup work2Group = null;
WorkGroup work3Group = null;
boolean work1found = false;
boolean work2found = false;
boolean work3found = false;
List<Long> putCodes = new ArrayList<Long>();
for (WorkGroup group : activities.getWorks().getWorkGroup()) {
if (group.getIdentifiers().getIdentifier() == null || group.getIdentifiers().getIdentifier().isEmpty()) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 2" + time).equals(title)) {
work2found = true;
work2Group = group;
putCodes.add(summary.getPutCode());
}
}
} else {
for (Identifier id : group.getIdentifiers().getIdentifier()) {
// If it is the ID is the one we are looking for
if (id.getExternalIdentifierId().equals("Work Id " + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 1" + time).equals(title)) {
work1found = true;
work1Group = group;
putCodes.add(summary.getPutCode());
} else if (("Work # 3" + time).equals(title)) {
work3found = true;
work3Group = group;
putCodes.add(summary.getPutCode());
}
}
}
}
}
}
assertTrue("Work1: " + work1found + " work2 " + work2found + " work3 " + work3found, work1found && work2found && work3found);
// Check that work # 1 and Work # 3 are in the same work
assertEquals(work1Group, work3Group);
// Check that work # 2 is not in the same group than group # 1
assertThat(work2Group, not(work1Group));
// Delete all elements created
for (Long putCode : putCodes) {
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessTokenForClient1);
if (Response.Status.NO_CONTENT.getStatusCode() != deleteResponse.getStatus()) {
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessTokenForClient2);
assertEquals("Cant delete work " + putCode, Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
}
}
use of org.geotoolkit.sml.xml.v100.Identifier in project cxf by apache.
the class RMCaptureOutInterceptor method handle.
protected void handle(Message msg) throws SequenceFault, RMException {
AddressingProperties maps = ContextUtils.retrieveMAPs(msg, false, true, false);
if (null == maps) {
LogUtils.log(LOG, Level.WARNING, "MAPS_RETRIEVAL_FAILURE_MSG");
return;
}
if (Boolean.TRUE.equals(msg.get(RMMessageConstants.RM_RETRANSMISSION))) {
return;
}
if (isRuntimeFault(msg)) {
LogUtils.log(LOG, Level.WARNING, "RUNTIME_FAULT_MSG");
// in case of a SequenceFault or other WS-RM related fault, set action appropriately.
// the received inbound maps is available to extract some values in case if needed.
Throwable cause = msg.getContent(Exception.class).getCause();
if (cause instanceof SequenceFault || cause instanceof RMException) {
maps.getAction().setValue(getAddressingNamespace(maps) + "/fault");
}
return;
}
Source source = getManager().getSource(msg);
RMConfiguration config = getManager().getEffectiveConfiguration(msg);
String wsaNamespace = config.getAddressingNamespace();
String rmNamespace = config.getRMNamespace();
ProtocolVariation protocol = ProtocolVariation.findVariant(rmNamespace, wsaNamespace);
RMContextUtils.setProtocolVariation(msg, protocol);
maps.exposeAs(wsaNamespace);
String action = null;
if (null != maps.getAction()) {
action = maps.getAction().getValue();
}
// make sure we use the appropriate namespace
maps.exposeAs(wsaNamespace);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Action: " + action);
}
boolean isApplicationMessage = !RMContextUtils.isRMProtocolMessage(action);
boolean isPartialResponse = MessageUtils.isPartialResponse(msg);
RMConstants constants = protocol.getConstants();
boolean isLastMessage = RM10Constants.CLOSE_SEQUENCE_ACTION.equals(action);
RMProperties rmpsOut = RMContextUtils.retrieveRMProperties(msg, true);
if (null == rmpsOut) {
rmpsOut = new RMProperties();
rmpsOut.exposeAs(protocol.getWSRMNamespace());
RMContextUtils.storeRMProperties(msg, rmpsOut, true);
}
// Activate process response for oneWay
if (msg.getExchange().isOneWay()) {
msg.getExchange().put(Message.PROCESS_ONEWAY_RESPONSE, true);
}
RMProperties rmpsIn = null;
Identifier inSeqId = null;
long inMessageNumber = 0;
if (isApplicationMessage) {
rmpsIn = RMContextUtils.retrieveRMProperties(msg, false);
if (null != rmpsIn && null != rmpsIn.getSequence()) {
inSeqId = rmpsIn.getSequence().getIdentifier();
inMessageNumber = rmpsIn.getSequence().getMessageNumber();
}
ContextUtils.storeDeferUncorrelatedMessageAbort(msg);
}
Map<?, ?> invocationContext = (Map<?, ?>) msg.get(Message.INVOCATION_CONTEXT);
if ((isApplicationMessage || (isLastMessage && invocationContext != null)) && !isPartialResponse) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("inbound sequence: " + (null == inSeqId ? "null" : inSeqId.getValue()));
}
// get the current sequence, requesting the creation of a new one if necessary
synchronized (source) {
final SourceSequence seq;
if (isLastMessage) {
seq = (SourceSequence) invocationContext.get(SourceSequence.class.getName());
} else {
seq = getManager().getSequence(inSeqId, msg, maps);
}
assert null != seq;
// increase message number and store a sequence type object in
// context
seq.nextMessageNumber(inSeqId, inMessageNumber, isLastMessage);
if (Boolean.TRUE.equals(msg.getContextualProperty(RMManager.WSRM_LAST_MESSAGE_PROPERTY))) {
// mark the message as the last one
seq.setLastMessage(true);
}
rmpsOut.setSequence(seq);
if (seq.isLastMessage()) {
source.setCurrent(null);
}
}
} else if (!MessageUtils.isRequestor(msg) && constants.getCreateSequenceAction().equals(action)) {
maps.getAction().setValue(constants.getCreateSequenceResponseAction());
} else if (isPartialResponse && action == null && isResponseToAction(msg, constants.getSequenceAckAction())) {
Collection<SequenceAcknowledgement> acks = rmpsIn != null ? rmpsIn.getAcks() : null;
if (acks != null && acks.size() == 1) {
SourceSequence ss = source.getSequence(acks.iterator().next().getIdentifier());
if (ss != null && ss.allAcknowledged()) {
setAction(maps, constants.getTerminateSequenceAction());
setTerminateSequence(msg, ss.getIdentifier(), protocol);
msg.remove(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE);
// removing this sequence now. See the comment in SourceSequence.setAcknowledged()
source.removeSequence(ss);
}
}
}
// capture message if retransmission possible
if (isApplicationMessage && !isPartialResponse) {
OutputStream os = msg.getContent(OutputStream.class);
// message until connection is setup
if (!(os instanceof WriteOnCloseOutputStream)) {
msg.setContent(OutputStream.class, new WriteOnCloseOutputStream(os));
}
getManager().initializeInterceptorChain(msg);
// doneCaptureMessage(msg);
captureMessage(msg);
} else if (isLastMessage) {
// got either the rm11 CS or the rm10 empty LM
RMStore store = getManager().getStore();
if (null != store) {
store.persistOutgoing(rmpsOut.getSourceSequence(), null);
}
}
}
use of org.geotoolkit.sml.xml.v100.Identifier in project cxf by apache.
the class RMOutInterceptor method addAckRequest.
/**
* Add AcknowledgementRequested to message if needed. The AckRequest mode set either in the message
* properties or in the source policy is used to determine whether AcknowledgementRequested is always
* added, never added, or added only when we're waiting for the acknowledgement to a previously-sent
* message.
*
* @param msg
* @param rmpsIn
* @param seq
* @param sequence
*/
protected void addAckRequest(Message msg, RMProperties rmpsIn, SourceSequence seq, SequenceType sequence) {
AckRequestModeType mode = (AckRequestModeType) msg.get(RMMessageConstants.ACK_REQUEST_MODE);
if (mode == null) {
mode = AckRequestModeType.PENDING;
SourcePolicyType policy = getManager().getSourcePolicy();
if (policy.isSetAckRequestMode()) {
mode = policy.getAckRequestMode();
}
}
if (AckRequestModeType.ALWAYS == mode || (mode == AckRequestModeType.PENDING && seq.needAcknowledge(rmpsIn.getMessageNumber()))) {
Collection<AckRequestedType> reqs = rmpsIn.getAcksRequested();
if (reqs == null) {
reqs = new ArrayList<>();
}
Identifier identifier = new Identifier();
identifier.setValue(sequence.getIdentifier().getValue());
AckRequestedType ackRequest = new AckRequestedType();
ackRequest.setIdentifier(identifier);
reqs.add(ackRequest);
rmpsIn.setAcksRequested(reqs);
}
}
use of org.geotoolkit.sml.xml.v100.Identifier in project cxf by apache.
the class Servant method clearUnattachedIdentifier.
Identifier clearUnattachedIdentifier() {
Identifier ret = unattachedIdentifier;
unattachedIdentifier = null;
return ret;
}
Aggregations