/** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(CmsRelation r1, CmsRelation r2) { if (r1 == r2) { return 0; } String p1 = r1.getSourcePath() + r1.getTargetPath() + r1.getType().getId(); String p2 = r2.getSourcePath() + r2.getTargetPath() + r2.getType().getId(); return p1.compareTo(p2); } };
/** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object o1, Object o2) { if ((o1 == o2) || !(o1 instanceof CmsRelation) || !(o2 instanceof CmsRelation)) { return 0; } CmsRelation r1 = (CmsRelation)o1; String p1 = r1.getSourcePath() + r1.getTargetPath() + r1.getType().getId(); CmsRelation r2 = (CmsRelation)o2; String p2 = r2.getSourcePath() + r2.getTargetPath() + r2.getType().getId(); return p1.compareTo(p2); } };
CmsRelation relation = (CmsRelation)itRelations.next(); String resourceName = relation.getSourcePath(); List broken = (List)brokenRelations.get(resourceName); if (broken == null) {
CmsRelation relation = itRelations.next(); String resourceName = relation.getSourcePath(); List<CmsRelation> broken = brokenRelations.get(resourceName); if (broken == null) {
/** * Creates a user-readable name from the given relation object.<p> * * @param relation the relation object * * @return the readable name */ protected String createReadableName(CmsRelation relation) { return relation.getType().getName() + "[ " + relation.getSourcePath() + " -> " + relation.getTargetPath() + " ]"; }
/** * Finds relations from the target root folder or its children to the source root folder or its children.<p> * * @return the list of relations from the target to the source * * @throws CmsException if something goes wrong */ protected List<CmsRelation> findRelationsFromTargetToSource() throws CmsException { List<CmsRelation> relations = m_cms.readRelations( CmsRelationFilter.SOURCES.filterPath(m_targetPath).filterIncludeChildren()); List<CmsRelation> result = new ArrayList<CmsRelation>(); for (CmsRelation rel : relations) { if (isInTargets(rel.getSourcePath()) && isInSources(rel.getTargetPath())) { result.add(rel); } } return result; }
ous.add(m_driverManager.readOrganizationalUnit( dbc, rel.getSourcePath().substring(CmsUserDriver.ORGUNIT_BASE_FOLDER.length()))); } catch (CmsException e) {
CmsRelationFilter.ALL.filterType(CmsRelationType.LOCALE_VARIANT)); for (CmsRelation rel : localeRelations) { if (isInSources(rel.getSourcePath()) && isInSources(rel.getTargetPath())) { CmsResource newRelationSource = m_translationsById.get(rel.getSourceId()); CmsResource newRelationTarget = m_translationsById.get(rel.getTargetId());
String relationName = relation.getSourcePath(); if (relationName.startsWith(infoEntry.getSiteRoot())) {
String relationName = relation.getSourcePath(); if (relationName.startsWith(infoEntry.getSiteRoot())) {
m_driverManager.readOrganizationalUnit( dbc, rel.getSourcePath().substring(CmsUserDriver.ORGUNIT_BASE_FOLDER.length()))); } catch (CmsException e) {
/** * Rewrites relations which are not derived from links in the content itself.<p> * * @param res the resource for which to rewrite the relations * @param relations the original relations * * @throws CmsException if something goes wrong */ protected void rewriteOtherRelations(CmsResource res, Collection<CmsRelation> relations) throws CmsException { LOG.info("Rewriting non-content links for " + res.getRootPath()); for (CmsRelation rel : relations) { CmsUUID targetId = rel.getTargetId(); CmsResource newTargetResource = m_translationsById.get(targetId); CmsRelationType relType = rel.getType(); if (!relType.isDefinedInContent()) { if (newTargetResource != null) { m_cms.deleteRelationsFromResource( rel.getSourcePath(), CmsRelationFilter.TARGETS.filterStructureId(rel.getTargetId()).filterType(relType)); m_cms.addRelationToResource( rel.getSourcePath(), newTargetResource.getRootPath(), relType.getName()); } } } } }
/** * @see org.opencms.db.I_CmsVfsDriver#createRelation(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.relations.CmsRelation) */ public void createRelation(CmsDbContext dbc, CmsUUID projectId, CmsRelation relation) throws CmsDataAccessException { Connection conn = null; PreparedStatement stmt = null; try { conn = m_sqlManager.getConnection(dbc); stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_CREATE_RELATION"); stmt.setString(1, relation.getSourceId().toString()); stmt.setString(2, relation.getSourcePath()); stmt.setString(3, relation.getTargetId().toString()); stmt.setString(4, relation.getTargetPath()); stmt.setInt(5, relation.getType().getId()); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key( Messages.LOG_CREATE_RELATION_2, String.valueOf(projectId), relation)); } stmt.executeUpdate(); } catch (SQLException e) { throw new CmsDbSqlException(Messages.get().container( Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e); } finally { m_sqlManager.closeAll(dbc, conn, stmt, null); } }
String relationName; if (isDeleted) { relationName = relation.getSourcePath(); } else { relationName = relation.getTargetPath();
CmsRelation rel = internalReadRelation(res); try { ous.add(m_driverManager.readOrganizationalUnit(dbc, rel.getSourcePath().substring( CmsUserDriver.ORGUNIT_BASE_FOLDER.length()))); } catch (CmsException e) {
LOG.info( "Found relation which needs to be corrected: " + relation.getSourcePath() + " -> " + relation.getTargetPath()
/** * Returns the source resource when possible to read with the given filter.<p> * * @param cms the current user context * @param filter the filter to use * * @return the source resource * * @throws CmsException if something goes wrong */ public CmsResource getSource(CmsObject cms, CmsResourceFilter filter) throws CmsException { try { // first look up by id return cms.readResource(getSourceId(), filter); } catch (CmsVfsResourceNotFoundException e) { // then look up by name, but from the root site String storedSiteRoot = cms.getRequestContext().getSiteRoot(); try { cms.getRequestContext().setSiteRoot(""); return cms.readResource(getSourcePath(), filter); } finally { cms.getRequestContext().setSiteRoot(storedSiteRoot); } } }
/** * Returns the source resource when possible to read with the given filter.<p> * * @param cms the current user context * @param filter the filter to use * * @return the source resource * * @throws CmsException if something goes wrong */ public CmsResource getSource(CmsObject cms, CmsResourceFilter filter) throws CmsException { try { // first look up by id return cms.readResource(getSourceId(), filter); } catch (CmsVfsResourceNotFoundException e) { // then look up by name, but from the root site String storedSiteRoot = cms.getRequestContext().getSiteRoot(); try { cms.getRequestContext().setSiteRoot(""); return cms.readResource(getSourcePath(), filter); } finally { cms.getRequestContext().setSiteRoot(storedSiteRoot); } } }
/** * @see org.opencms.db.I_CmsVfsDriver#createRelation(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.relations.CmsRelation) */ public void createRelation(CmsDbContext dbc, CmsUUID projectId, CmsRelation relation) throws CmsDataAccessException { try { I_CmsDAOResourceRelations rr = CmsProject.isOnlineProject(projectId) ? new CmsDAOOnlineResourceRelations() : new CmsDAOOfflineResourceRelations(); rr.setRelationSourceId(relation.getSourceId().toString()); rr.setRelationSourcePath(relation.getSourcePath()); rr.setRelationTargetId(relation.getTargetId().toString()); rr.setRelationTargetPath(relation.getTargetPath()); rr.setRelationType(relation.getType().getId()); m_sqlManager.persist(dbc, rr); if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key( Messages.LOG_CREATE_RELATION_2, String.valueOf(projectId), relation)); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } }
resource.getStructureId(), CmsLogEntryType.RESOURCE_ADD_RELATION, new String[] {relation.getSourcePath(), relation.getTargetPath()}), false);