@ExceptionHandler(RelationshipConstraintException.class) public void handleException(RelationshipConstraintException e, HttpServletRequest req, HttpServletResponse resp) { log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]"); resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); try { resp.getWriter().print(e.getMessage()); resp.getWriter().flush(); resp.getWriter().close(); } catch (Exception ee) { log.debug("Handling exception", e); } }
@Override public String getProjectForCollection(String collectionId) throws RelationshipConstraintException { final Set<Relationship> rels; synchronized (IdBasedMutexFactory.create(collectionId)) { rels = relDao.getRelations(collectionId, IS_AGGREGATED_BY, RelationshipDAO.RelEnd.SOURCE); } // Make sure the collection belongs to only one project if (rels.size() > 1) { final String msg = String.format(ERR_CONSTRAINT_PROJECT_COLLECTION, collectionId); throw new RelationshipConstraintException(msg); } for (Relationship rel : rels) { return rel.getTarget(); } return null; }
@Override public String getProjectForCollection(String collectionId) throws RelationshipConstraintException { final Set<Relationship> rels; synchronized (IdBasedMutexFactory.create(collectionId)) { rels = relDao.getRelations(collectionId, IS_AGGREGATED_BY, RelationshipDAO.RelEnd.SOURCE); } // Make sure the collection belongs to only one project if (rels.size() > 1) { final String msg = String.format(ERR_CONSTRAINT_PROJECT_COLLECTION, collectionId); throw new RelationshipConstraintException(msg); } for (Relationship rel : rels) { return rel.getTarget(); } return null; }
@ExceptionHandler(RelationshipConstraintException.class) public void handleException(RelationshipConstraintException e, HttpServletRequest req, HttpServletResponse resp) { log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]"); resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); try { resp.getWriter().print(e.getMessage()); resp.getWriter().flush(); resp.getWriter().close(); } catch (Exception ee) { log.debug("Handling exception", e); } }
@Override public void addMetadataFileToBusinessObject(String metadataFileId, String businessObjectId) throws RelationshipConstraintException{ synchronized (IdBasedMutexFactory.create(metadataFileId, businessObjectId)) { final Set<Relationship> existingRelations = relDao.getRelations(metadataFileId, HAS_METADATA_FILE, RelEnd.TARGET); // Make sure the MetadataFile doesn't already belong to another BusinessObject if (!existingRelations.isEmpty()) { Relationship rel = existingRelations.iterator().next(); if (!rel.getSource().equals(businessObjectId)) { final String msg = String.format(ERR_CONSTRAINT_METADATAFILE, metadataFileId, businessObjectId, rel.getSource()); throw new RelationshipConstraintException(msg); } } relDao.addRelation(businessObjectId, metadataFileId, HAS_METADATA_FILE); } }
throw new BizInternalException("Error occurred when checking for CREATE permission of provided user. " + e.getMessage()); log.warn( "Could not update collection relationships for Collection (" + collection.getId() + "): " + e.getMessage(), e);
@Override public void addMetadataFileToBusinessObject(String metadataFileId, String businessObjectId) throws RelationshipConstraintException{ synchronized (IdBasedMutexFactory.create(metadataFileId, businessObjectId)) { final Set<Relationship> existingRelations = relDao.getRelations(metadataFileId, HAS_METADATA_FILE, RelEnd.TARGET); // Make sure the MetadataFile doesn't already belong to another BusinessObject if (!existingRelations.isEmpty()) { Relationship rel = existingRelations.iterator().next(); if (!rel.getSource().equals(businessObjectId)) { final String msg = String.format(ERR_CONSTRAINT_METADATAFILE, metadataFileId, businessObjectId, rel.getSource()); throw new RelationshipConstraintException(msg); } } relDao.addRelation(businessObjectId, metadataFileId, HAS_METADATA_FILE); } }
throw new BizInternalException("Error occurred when checking for CREATE permission of provided user. " + e.getMessage()); log.warn( "Could not update collection relationships for Collection (" + collection.getId() + "): " + e.getMessage(), e);
@Override public void addRelationshipSetForBusinessObject(String businessObjectId, String relationshipSetId) throws RelationshipException, IllegalArgumentException { if (businessObjectId == null || relationshipSetId == null) { throw new IllegalArgumentException("ids cannot be null!"); } Set<Relationship> boRels = relDao.getRelations(businessObjectId, Relationship.RelType.HAS_RELATIONSHIP_SET); for (Relationship rel : boRels) { if (rel.getSubject().equals(businessObjectId)) { throw new RelationshipConstraintException("A business object cannot have multiple relationship sets"); } } Set<Relationship> rsRels = relDao.getRelations(relationshipSetId, Relationship.RelType.HAS_RELATIONSHIP_SET); for (Relationship rel : rsRels) { if (rel.getObject().equals(relationshipSetId)) { throw new RelationshipConstraintException("A relationship set cannot be mapped to more than one business object"); } } relDao.addRelation(businessObjectId, relationshipSetId, Relationship.RelType.HAS_RELATIONSHIP_SET); }
@Override public void addRelationshipSetForBusinessObject(String businessObjectId, String relationshipSetId) throws RelationshipException, IllegalArgumentException { if (businessObjectId == null || relationshipSetId == null) { throw new IllegalArgumentException("ids cannot be null!"); } Set<Relationship> boRels = relDao.getRelations(businessObjectId, Relationship.RelType.HAS_RELATIONSHIP_SET); for (Relationship rel : boRels) { if (rel.getSubject().equals(businessObjectId)) { throw new RelationshipConstraintException("A business object cannot have multiple relationship sets"); } } Set<Relationship> rsRels = relDao.getRelations(relationshipSetId, Relationship.RelType.HAS_RELATIONSHIP_SET); for (Relationship rel : rsRels) { if (rel.getObject().equals(relationshipSetId)) { throw new RelationshipConstraintException("A relationship set cannot be mapped to more than one business object"); } } relDao.addRelation(businessObjectId, relationshipSetId, Relationship.RelType.HAS_RELATIONSHIP_SET); }
throw new RelationshipConstraintException("Exception occured when looking up super collection. \n" + e);
throw new RelationshipConstraintException(msg);
throw new RelationshipConstraintException("Exception occured when looking up super collection. \n" + e);
@Override public Project getProjectForCollection(Collection collection) throws RelationshipConstraintException { final Set<Relationship> rels; synchronized (IdBasedMutexFactory.create(collection)) { rels = relDao.getRelations(collection.getId(), IS_AGGREGATED_BY, RelationshipDAO.RelEnd.SOURCE); } // Make sure the collection belongs to only one project if (rels.size() > 1) { final String msg = String.format(ERR_CONSTRAINT_PROJECT_COLLECTION, collection.getId()); throw new RelationshipConstraintException(msg); } Project project = new Project(); for (Relationship rel : rels) { Project p = lookupProject(rel.getTarget()); if (p != null) { project = p; } } return project; }
@Override public Project getProjectForCollection(Collection collection) throws RelationshipConstraintException { final Set<Relationship> rels; synchronized (IdBasedMutexFactory.create(collection)) { rels = relDao.getRelations(collection.getId(), IS_AGGREGATED_BY, RelationshipDAO.RelEnd.SOURCE); } // Make sure the collection belongs to only one project if (rels.size() > 1) { final String msg = String.format(ERR_CONSTRAINT_PROJECT_COLLECTION, collection.getId()); throw new RelationshipConstraintException(msg); } Project project = new Project(); for (Relationship rel : rels) { Project p = lookupProject(rel.getTarget()); if (p != null) { project = p; } } return project; }
throw new RelationshipConstraintException(msg);
throw new RelationshipConstraintException("Exception occured when looking up super collection. \n" + e);
throw new RelationshipConstraintException("Exception occured when looking up super collection. \n" + e);