/** * 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; }
/** * Creates a relation id from the given OpenCms relation object.<p> * * @param relation the OpenCms relation object * * @return the relation id */ String createKey(CmsRelation relation) { return createKey(relation.getSourceId(), relation.getTargetId(), relation.getType().getName()); }
if (isInSources(rel.getSourcePath()) && isInSources(rel.getTargetPath())) { CmsResource newRelationSource = m_translationsById.get(rel.getSourceId()); CmsResource newRelationTarget = m_translationsById.get(rel.getTargetId()); if ((newRelationSource != null) && (newRelationTarget != null)) { try {
/** * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.file.CmsObject, java.util.List) */ public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) { CmsMenuItemVisibilityMode visibility = VISIBILITY.getVisibility(cms, resources); if (visibility.isInVisible() || visibility.isInActive()) { return visibility; } try { List<CmsRelation> relations = readOutgoingRelations(cms, resources.get(0)); boolean hasRelations = false; for (CmsRelation relation : relations) { if (!relation.getTargetId().isNullUUID()) { hasRelations = true; break; } } return hasRelations ? CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE : CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE; } }
List<CmsRelation> relations = new ArrayList<CmsRelation>(); for (CmsRelation relation : unfilteredRelations) { if (relation.getTargetId().isNullUUID() || relation.getSourceId().isNullUUID()) { continue;
/** * 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); } }
for (CmsRelation relation : relations) { LOG.info("Trying to read resource for relation " + relation.getTargetPath()); CmsResource target = getResource(relation.getTargetId()); if (target != null) { if (relation.getType().isStrong() || shouldAddWeakRelationTarget(target)) {
/** * 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); }
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()); stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RELATIONS_NORMALIZE_LOCALE_RELATIONS"); stmt.setString(1, relation.getSourceId().toString()); stmt.setString(2, relation.getTargetId().toString()); stmt.setString(3, relation.getSourceId().toString()); stmt.setString(4, relation.getTargetId().toString()); if (LOG.isDebugEnabled()) { LOG.debug(
if (!relation.getTargetId().isNullUUID()) { filter = filter.filterStructureId(relation.getTargetId());
dbc, project.getUuid(), relation.getTargetId(), true).getRootPath(); } catch (CmsVfsResourceNotFoundException e) { Messages.get().getBundle().key( Messages.LOG_LINK_VALIDATION_READBYID_FAILED_2, relation.getTargetId().toString(), project.getName()), e);
if (!relation.getTargetId().isNullUUID()) { filter = filter.filterStructureId(relation.getTargetId());
sibling.getStructureId(), sibling.getRootPath(), originalRelation.getTargetId(), originalRelation.getTargetPath(), link.getType());
sibling.getStructureId(), sibling.getRootPath(), originalRelation.getTargetId(), originalRelation.getTargetPath(), link.getType());
/** * 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); } }
for (CmsRelation relation : relations) { CmsUUID sourceId = relation.getSourceId(); CmsUUID targetId = relation.getTargetId(); CmsResource resourceToModify = null; if (sourceId.equals(firstId) && targetId.equals(secondId)) {
addPropertyId(tm, result, typeId, filter, PropertyIds.TARGET_ID, relation.getTargetId().toString());