Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issv3 hibernate schema #9375

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
import com.suse.manager.model.attestation.CoCoResultTypeConverter;
import com.suse.manager.model.attestation.ServerCoCoAttestationConfig;
import com.suse.manager.model.attestation.ServerCoCoAttestationReport;
import com.suse.manager.model.hub.IssHub;
import com.suse.manager.model.hub.IssPeripheral;
import com.suse.manager.model.hub.IssPeripheralChannels;
import com.suse.manager.model.maintenance.MaintenanceCalendar;
import com.suse.manager.model.maintenance.MaintenanceSchedule;

Expand Down Expand Up @@ -203,7 +206,10 @@ private AnnotationRegistry() {
ServerAppStream.class,
AppStream.class,
AppStreamApi.class,
TokenChannelAppStream.class
TokenChannelAppStream.class,
IssHub.class,
IssPeripheral.class,
IssPeripheralChannels.class
);

/**
Expand Down
88 changes: 88 additions & 0 deletions java/code/src/com/suse/manager/model/hub/HubFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2024 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/
package com.suse.manager.model.hub;

import com.redhat.rhn.common.hibernate.HibernateFactory;
import com.redhat.rhn.domain.channel.Channel;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;
import java.util.Optional;

public class HubFactory extends HibernateFactory {

private static final Logger LOG = LogManager.getLogger(HubFactory.class);

@Override
protected Logger getLogger() {
return LOG;
}

/**
* Save a {@link IssHub} object
* @param issHubIn object to save
*/
public void save(IssHub issHubIn) {
saveObject(issHubIn);
}

/**
* Save a {@link IssPeripheral} object
* @param issPeripheralIn object to save
*/
public void save(IssPeripheral issPeripheralIn) {
saveObject(issPeripheralIn);
}

/**
* Save a {@link IssPeripheralChannels} object
* @param issPeripheralChannelsIn object to save
*/
public void save(IssPeripheralChannels issPeripheralChannelsIn) {
saveObject(issPeripheralChannelsIn);
}

/**
* Lookup {@link IssHub} object by its FQDN
* @param fqdnIn the fqdn
* @return return {@link IssHub} with the given FQDN or empty
*/
public Optional<IssHub> lookupIssHubByFqdn(String fqdnIn) {
return getSession().createQuery("FROM IssHub WHERE fqdn = :fqdn", IssHub.class)
.setParameter("fqdn", fqdnIn)
.uniqueResultOptional();
}

/**
* Lookup {@link IssPeripheral} object by its FQDN
* @param fqdnIn the fqdn
* @return return {@link IssPeripheral} with the given FQDN or empty
*/
public Optional<IssPeripheral> lookupIssPeripheralByFqdn(String fqdnIn) {
return getSession().createQuery("FROM IssPeripheral WHERE fqdn = :fqdn", IssPeripheral.class)
.setParameter("fqdn", fqdnIn)
.uniqueResultOptional();
}

/**
* List {@link IssPeripheralChannels} objects which reference the given {@link Channel}
* @param channelIn the channel
* @return return the list of {@link IssPeripheralChannels} objects
*/
public List<IssPeripheralChannels> listIssPeripheralChannelsByChannels(Channel channelIn) {
return getSession()
.createQuery("FROM IssPeripheralChannels WHERE channel = :channel", IssPeripheralChannels.class)
.setParameter("channel", channelIn)
.list();
}
}
149 changes: 149 additions & 0 deletions java/code/src/com/suse/manager/model/hub/IssHub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2024 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/
package com.suse.manager.model.hub;

import com.redhat.rhn.domain.BaseDomainHelper;
import com.redhat.rhn.domain.credentials.SCCCredentials;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "suseISSHub")
public class IssHub extends BaseDomainHelper {
private Long id;
private String fqdn;
private String rootCa;
private SCCCredentials mirrorCredentials;

protected IssHub() {
// Default empty Constructor for Hibernate
}

/**
* Constructor
* @param fqdnIn the FQDN of the Hub Server
*/
public IssHub(String fqdnIn) {
this (fqdnIn, null);
}

/**
* Constructor
* @param fqdnIn the FQDN of the Hub Server
* @param rootCaIn the root CA used by the Hub Server
*/
public IssHub(String fqdnIn, String rootCaIn) {
fqdn = fqdnIn;
rootCa = rootCaIn;
mirrorCredentials = null;
}

/**
* @return return the ID
*/
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

/**
* Get the FQDN of the Hub Server
* @return return the FQDN of the Hub Server
*/
@Column(name = "fqdn", unique = true)
public String getFqdn() {
return fqdn;
}

/**
* Get the configured Root CA
* @return return the root ca
*/
@Column(name = "root_ca")
public String getRootCa() {
return rootCa;
}

/**
* Get the mirror credentials.
* @return the credentials
*/
@ManyToOne(targetEntity = SCCCredentials.class)
@JoinColumn(name = "mirror_creds_id")
public SCCCredentials getMirrorCredentials() {
return mirrorCredentials;
}

/*
* will be autogenerated
*/
protected void setId(Long idIn) {
id = idIn;
}

/**
* @param fqdnIn the FQDN
*/
public void setFqdn(String fqdnIn) {
fqdn = fqdnIn;
}

/**
* @param rootCaIn the root ca
*/
public void setRootCa(String rootCaIn) {
rootCa = rootCaIn;
}

/**
* @param mirrorCredentialsIn the mirror credentials
*/
public void setMirrorCredentials(SCCCredentials mirrorCredentialsIn) {
mirrorCredentials = mirrorCredentialsIn;
}

@Override
public boolean equals(Object oIn) {
if (this == oIn) {
return true;
}
if (!(oIn instanceof IssHub issHub)) {
return false;
}
return Objects.equals(getFqdn(), issHub.getFqdn()) &&
Objects.equals(getRootCa(), issHub.getRootCa()) &&
Objects.equals(getMirrorCredentials(), issHub.getMirrorCredentials());
}

@Override
public int hashCode() {
return Objects.hash(getFqdn(), getRootCa(), getMirrorCredentials());
}

@Override
public String toString() {
return "IssHub{" +
"id=" + id +
", fqdn='" + fqdn + '\'' +
'}';
}
}
Loading
Loading