/** * Returns the list of root paths associated to the organizational unit represented by the given resource.<p> * * @param dbc the current db context * @param ouResource the resource that represents the organizational unit to get the resources for * * @return the list of associated resource names * * @throws CmsException if something goes wrong */ protected List<String> internalResourcesForOrgUnit(CmsDbContext dbc, CmsResource ouResource) throws CmsException { List<CmsRelation> relations = m_driverManager.getRelationsForResource( dbc, ouResource, CmsRelationFilter.TARGETS); List<String> paths = new ArrayList<String>(); Iterator<CmsRelation> it = relations.iterator(); while (it.hasNext()) { CmsRelation relation = it.next(); paths.add(relation.getTargetPath()); } return paths; }
/** * Returns the list of root paths associated to the organizational unit represented by the given resource.<p> * * @param dbc the current db context * @param ouResource the resource that represents the organizational unit to get the resources for * * @return the list of associated resource names * * @throws CmsException if something goes wrong */ protected List internalResourcesForOrgUnit(CmsDbContext dbc, CmsResource ouResource) throws CmsException { List relations = m_driverManager.getRelationsForResource(dbc, ouResource, CmsRelationFilter.TARGETS); List paths = new ArrayList(); Iterator it = relations.iterator(); while (it.hasNext()) { CmsRelation relation = (CmsRelation)it.next(); paths.add(relation.getTargetPath()); } return paths; }
/** * Returns the list of root paths associated to the organizational unit represented by the given resource.<p> * * @param dbc the current db context * @param ouResource the resource that represents the organizational unit to get the resources for * * @return the list of associated resource names * * @throws CmsException if something goes wrong */ protected List<String> internalResourcesForOrgUnit(CmsDbContext dbc, CmsResource ouResource) throws CmsException { List<CmsRelation> relations = m_driverManager.getRelationsForResource( dbc, ouResource, CmsRelationFilter.TARGETS); List<String> paths = new ArrayList<String>(); Iterator<CmsRelation> it = relations.iterator(); while (it.hasNext()) { CmsRelation relation = it.next(); paths.add(relation.getTargetPath()); } return paths; }
/** * @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); } };
/** * Creates a publish resource bean from the target information of a relation object.<p> * * @param relation the relation to use * * @return the publish resource bean for the relation target * * @throws CmsException if something goes wrong */ public CmsPublishResource relationToBean(CmsRelation relation) throws CmsException { CmsPermissionInfo permissionInfo = new CmsPermissionInfo(true, false, ""); return new CmsPublishResource( relation.getTargetId(), relation.getTargetPath(), relation.getTargetPath(), CmsResourceTypePlain.getStaticTypeName(), null, CmsResourceState.STATE_UNCHANGED, permissionInfo, 0, null, null, false, null, 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() + " ]"; }
/** * Checks a link to a resource which has been deleted.<p> * @param relation * * @param link the URI of the resource which has a link to the deleted resource * @param fileLookup a lookup table of files to be published * @param relationTargets * * @return true if the resource which has a link to the deleted resource is also going to be deleted */ protected boolean checkLinkForDeletedLinkTarget( CmsRelation relation, String link, Map<String, CmsResource> fileLookup, HashMultimap<String, String> relationTargets) { boolean isValidLink = false; // since we are going to delete the resource // check if the linked resource is also to be deleted if (fileLookup.containsKey(link)) { CmsResource offlineResource = fileLookup.get(link); Set<String> relationTargetsForLink = relationTargets.get(link); boolean hasNoRelations = !relationTargetsForLink.contains(relation.getTargetPath()) && !relationTargetsForLink.contains(relation.getTargetId().toString()); isValidLink = offlineResource.getState().isDeleted() || hasNoRelations; } return isValidLink; }
/** * 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; }
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());
/** * @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); } }
relationName = relation.getSourcePath(); } else { relationName = relation.getTargetPath();
List<CmsRelation> relations = getRelationsFromResource(currentResource); for (CmsRelation relation : relations) { LOG.info("Trying to read resource for relation " + relation.getTargetPath()); CmsResource target = getResource(relation.getTargetId()); if (target != null) {
while (j.hasNext()) { CmsRelation brokenLink = (CmsRelation)j.next(); String link = brokenLink.getTargetPath(); String siteRoot = OpenCms.getSiteManager().getSiteRoot(link); String siteName = siteRoot;
e); m_driverManager.getVfsDriver(dbc).readResource(dbc, project.getUuid(), relation.getTargetPath(), true); Messages.get().getBundle().key( Messages.LOG_LINK_VALIDATION_READBYPATH_FAILED_2, relation.getTargetPath(), project.getName()), e);
+ relation.getSourcePath() + " -> " + relation.getTargetPath() + " [" + relation.getType().getName()
/** * Returns the target resource when possible to read with the given filter.<p> * * @param cms the current user context * @param filter the filter to use * * @return the target resource * * @throws CmsException if something goes wrong */ public CmsResource getTarget(CmsObject cms, CmsResourceFilter filter) throws CmsException { try { // first look up by id return cms.readResource(getTargetId(), 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(getTargetPath(), filter); } finally { cms.getRequestContext().setSiteRoot(storedSiteRoot); } } }
/** * Returns the target resource when possible to read with the given filter.<p> * * @param cms the current user context * @param filter the filter to use * * @return the target resource * * @throws CmsException if something goes wrong */ public CmsResource getTarget(CmsObject cms, CmsResourceFilter filter) throws CmsException { try { // first look up by id return cms.readResource(getTargetId(), 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(getTargetPath(), 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);