本文整理汇总了Java中org.ndexbio.model.exceptions.DuplicateObjectException类的典型用法代码示例。如果您正苦于以下问题:Java DuplicateObjectException类的具体用法?Java DuplicateObjectException怎么用?Java DuplicateObjectException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DuplicateObjectException类属于org.ndexbio.model.exceptions包,在下文中一共展示了DuplicateObjectException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test0002CreateDuplicateGroup
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
@Test
public void test0002CreateDuplicateGroup() throws JsonProcessingException, IOException, NdexException {
// create new group
newGroup = GroupUtils.createGroup(ndex, group);
// check the contents of the newly created Group object
GroupUtils.compareGroupObjectsContents(group, newGroup);
// expected exception is DuplicateObjectException
thrown.expect(DuplicateObjectException.class);
// expected message of DuplicateObjectException
thrown.expectMessage("Group with name " + groupName.toLowerCase() + " already exists.");
// create the same group again using ndex client
// expect DuplicateObjectException because group already exists on the server
UUID newGroupId = ndex.createGroup(group);
ndex.getGroup(newGroupId);
}
示例2: test0003CreateGroupWithInvalidName
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
/**
* Try to create a group with the same name as user/account name.
* DuplicateObjectException is expected.
*
* APIs tested: public Group createGroup(Group)
*
*/
@Test
public void test0003CreateGroupWithInvalidName() throws JsonProcessingException, IOException, NdexException {
newGroup = new Group();
// set the group name to be user/account name
newGroup.setGroupName(accountName);
// initialize other properties
newGroup.setDescription(group.getDescription());
newGroup.setImage(group.getImage());
newGroup.setGroupName(group.getGroupName());
newGroup.setWebsite(group.getWebsite());
// expected exception is DuplicateObjectException
thrown.expect(DuplicateObjectException.class);
// expected message of DuplicateObjectException
thrown.expectMessage("Group with name " + accountName.toLowerCase() + " already exists.");
// try to create new group with the same name as user/account
// exception is expected
ndex.createGroup(newGroup);
}
示例3: createRequest
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
/**************************************************************************
* Creates a request.
*
* @return The newly created request.
* @throws SQLException
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
**************************************************************************/
@POST
@Produces("application/json")
@ApiDoc("Create a new request based on a request JSON structure. Returns the JSON structure including the assigned UUID of this request."
+ "CreationDate, modificationDate, and sourceName fields will be ignored in the input object. A user can only create request for "
+ "himself or the group that he is a member of.")
public Request createRequest(final Request newRequest)
throws IllegalArgumentException, DuplicateObjectException, NdexException, SQLException, JsonParseException, JsonMappingException, IOException {
logger.info("[start: Creating request for {}]", newRequest.getDestinationName());
if ( newRequest.getRequestType() == null)
throw new NdexException ("RequestType is missing in the posted request object.");
try (RequestDAO dao = new RequestDAO ()){
Request request = dao.createRequest(newRequest, this.getLoggedInUser());
dao.commit();
return request;
} finally {
logger.info("[end: Request created]");
}
}
示例4: createNetworkSet
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
@POST
@Produces("text/plain")
public Response createNetworkSet(final NetworkSet newNetworkSet)
throws DuplicateObjectException,
NdexException, SQLException, JsonProcessingException {
if ( newNetworkSet.getName() == null || newNetworkSet.getName().length() == 0)
throw new NdexException ("Network set name is required.");
try (NetworkSetDAO dao = new NetworkSetDAO()){
UUID setId = NdexUUIDFactory.INSTANCE.createNewNDExUUID();
dao.createNetworkSet(setId, newNetworkSet.getName(), newNetworkSet.getDescription(), getLoggedInUserId(), newNetworkSet.getProperties());
dao.commit();
URI l = new URI (Configuration.getInstance().getHostURI() +
Configuration.getInstance().getRestAPIPrefix()+"/networkset/"+ setId.toString());
return Response.created(l).entity(l).build();
} catch (URISyntaxException e) {
throw new NdexException("Server Error, can create URL for the new resource: " + e.getMessage(), e);
}
}
示例5: updateNetworkSet
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
@PUT
@Path("/{networksetid}")
public void updateNetworkSet(final NetworkSet newNetworkSet,
@PathParam("networksetid") final String id)
throws DuplicateObjectException,
NdexException, SQLException, JsonProcessingException {
if ( newNetworkSet.getName() == null || newNetworkSet.getName().length() == 0)
throw new NdexException ("Network set name is required.");
UUID setId = UUID.fromString(id);
try (NetworkSetDAO dao = new NetworkSetDAO()){
if ( !dao.isNetworkSetOwner(setId, getLoggedInUserId()))
throw new UnauthorizedOperationException("Signed in user is not the owner of this network set.");
dao.updateNetworkSet(setId, newNetworkSet.getName(), newNetworkSet.getDescription(), getLoggedInUserId(),newNetworkSet.getProperties());
dao.commit();
return ;
}
}
示例6: addNetworksToSet
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
@POST
@Path("/{networksetid}/members")
@Produces("text/plain")
public Response addNetworksToSet(final List<UUID> networkIds,
@PathParam("networksetid") final String networkSetIdStr )
throws DuplicateObjectException,
NdexException, SQLException {
UUID setId = UUID.fromString(networkSetIdStr);
try (NetworkSetDAO dao = new NetworkSetDAO()){
if ( !dao.isNetworkSetOwner(setId, getLoggedInUserId()))
throw new UnauthorizedOperationException("Signed in user is not the owner of this network set.");
dao.addNetworksToNetworkSet(setId, networkIds);
dao.commit();
URI l = new URI (Configuration.getInstance().getHostURI() +
Configuration.getInstance().getRestAPIPrefix()+"/networkset/"+ setId.toString()+"/members");
return Response.created(l).entity(l).build();
} catch (URISyntaxException e) {
throw new NdexException("Server Error, can create URL for the new resource: " + e.getMessage(), e);
}
}
示例7: checkForExistingGroup
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private void checkForExistingGroup(final Group group)
throws IllegalArgumentException, NdexException, JsonParseException, JsonMappingException, SQLException, IOException {
Preconditions.checkArgument(null != group,
"UUID required");
try {
getGroupByGroupName(group.getGroupName());
String msg = "Group with name " + group.getGroupName() + " already exists.";
logger.info(msg);
throw new DuplicateObjectException(msg);
} catch ( ObjectNotFoundException e) {
// when account doesn't exists return as normal.
}
}
示例8: createNetworkSet
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
public void createNetworkSet(UUID setId, String name, String desc, UUID ownerId, Map<String,Object> properties) throws SQLException, DuplicateObjectException, JsonProcessingException {
Timestamp t = new Timestamp(System.currentTimeMillis());
checkDuplicateName(name,ownerId, null);
String sqlStr = "insert into network_set (\"UUID\", creation_time, modification_time, is_deleted, owner_id, name, description, other_attributes, showcased) values"
+ "(?, ?, ?, false, ?,?, ?,? :: jsonb, false ) ";
try (PreparedStatement pst = db.prepareStatement(sqlStr)) {
pst.setObject(1, setId);
pst.setTimestamp(2, t);
pst.setTimestamp(3, t);
pst.setObject(4, ownerId);
pst.setString(5, name);
pst.setString(6, desc);
ObjectMapper mapper = new ObjectMapper();
String s = properties ==null ? null : mapper.writeValueAsString(properties);
pst.setString(7, s);
pst.executeUpdate();
}
}
示例9: updateNetworkSet
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
public void updateNetworkSet(UUID setId, String name, String desc, UUID ownerId, Map<String,Object> properties) throws SQLException, DuplicateObjectException, JsonProcessingException {
Timestamp t = new Timestamp(System.currentTimeMillis());
checkDuplicateName(name, ownerId, setId);
String sqlStr = "update network_set set modification_time = ?, name = ?, description = ?, other_attributes=? :: jsonb where \"UUID\"=? and is_deleted=false";
try (PreparedStatement pst = db.prepareStatement(sqlStr)) {
pst.setTimestamp(1, t);
pst.setString(2, name);
pst.setString(3, desc);
ObjectMapper mapper = new ObjectMapper();
String s = properties ==null ? null : mapper.writeValueAsString(properties);
pst.setString(4, s);
pst.setObject(5, setId);
pst.executeUpdate();
}
}
示例10: createEdgeSupport
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private void createEdgeSupport(EdgeSupportLinksElement elmt) throws ObjectNotFoundException, DuplicateObjectException {
for ( Long sourceId : elmt.getSourceIds()) {
ODocument edgeDoc = getOrCreateEdgeDocBySID(sourceId);
Set<Long> supportIds = edgeDoc.field(NdexClasses.Support);
if(supportIds == null)
supportIds = new HashSet<>(elmt.getSupportIds().size());
for ( Long supportSID : elmt.getSupportIds()) {
Long supportId = supportSIDMap.get(supportSID);
if ( supportId == null) {
supportId = createSupportBySID(supportSID);
}
supportIds.add(supportId);
}
edgeDoc.field(NdexClasses.Support, supportIds).save();
}
}
示例11: createNodeSupport
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private void createNodeSupport(NodeSupportLinksElement elmt) throws ObjectNotFoundException, DuplicateObjectException {
for (Long sourceId : elmt.getSourceIds()) {
ODocument nodeDoc = getOrCreateNodeDocBySID(sourceId);
Set<Long> supportIds = nodeDoc.field(NdexClasses.Support);
if(supportIds == null)
supportIds = new HashSet<>(elmt.getSupportIds().size());
for ( Long supportSID : elmt.getSupportIds()) {
Long supportId = supportSIDMap.get(supportSID);
if ( supportId == null) {
supportId = createSupportBySID(supportSID);
}
supportIds.add(supportId);
}
nodeDoc.field(NdexClasses.Support, supportIds).save();
}
}
示例12: createEdgeCitation
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private void createEdgeCitation(EdgeCitationLinksElement elmt) throws DuplicateObjectException, ObjectNotFoundException {
for ( Long sourceId : elmt.getSourceIds()) {
ODocument edgeDoc = getOrCreateEdgeDocBySID(sourceId);
Set<Long> citationIds = edgeDoc.field(NdexClasses.Citation);
if(citationIds == null)
citationIds = new HashSet<>(elmt.getCitationIds().size());
for ( Long citationSID : elmt.getCitationIds()) {
Long citationId = citationSIDMap.get(citationSID);
if ( citationId == null) {
citationId = createCitationBySID(citationSID);
}
citationIds.add(citationId);
}
edgeDoc.field(NdexClasses.Citation, citationIds).save();
}
}
示例13: createNodeCitation
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private void createNodeCitation(NodeCitationLinksElement elmt) throws DuplicateObjectException, ObjectNotFoundException {
for ( Long sourceId : elmt.getSourceIds()) {
ODocument nodeDoc = getOrCreateNodeDocBySID(sourceId);
Set<Long> citationIds = nodeDoc.field(NdexClasses.Citation);
if(citationIds == null)
citationIds = new HashSet<>(elmt.getCitationIds().size());
for ( Long citationSID : elmt.getCitationIds()) {
Long citationId = citationSIDMap.get(citationSID);
if ( citationId == null) {
citationId = createCitationBySID(citationSID);
}
citationIds.add(citationId);
}
nodeDoc.field(NdexClasses.Citation, citationIds).save();
}
}
示例14: createCXContext
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private void createCXContext(NamespacesElement context) throws NdexException {
for ( Map.Entry<String, String> e : context.entrySet()) {
Long nsId = ndexdb.getNextId(localConnection);
ODocument nsDoc = new ODocument(NdexClasses.Namespace);
nsDoc = nsDoc.fields(NdexClasses.Element_ID,nsId,
NdexClasses.ns_P_prefix, e.getKey(),
NdexClasses.ns_P_uri, e.getValue())
.save();
OrientVertex nsV = graph.getVertex(nsDoc);
networkVertex.addEdge(NdexClasses.Network_E_Namespace, nsV);
Long oldv = this.namespaceMap.put(e.getKey(), nsId);
if ( oldv !=null)
throw new DuplicateObjectException("Duplicate @context prefix " + e.getKey());
tick();
}
}
示例15: createCitationBySID
import org.ndexbio.model.exceptions.DuplicateObjectException; //导入依赖的package包/类
private Long createCitationBySID(Long sid) throws DuplicateObjectException {
Long citationId = ndexdb.getNextId(localConnection);
// ODocument citationDoc =
new ODocument(NdexClasses.Citation)
.fields(NdexClasses.Element_ID, citationId,
NdexClasses.Element_SID, sid)
.save();
Long oldId = citationSIDMap.put(sid, citationId);
if ( oldId !=null)
throw new DuplicateObjectException(CitationElement.ASPECT_NAME, sid);
undefinedCitationId.add(sid);
return citationId;
}