diff --git a/src/main/java/org/nrg/xnat/daos/HostInfoDAO.java b/src/main/java/org/nrg/xnat/daos/HostInfoDAO.java index 106f8823cee9ec84de8cec2cdb46dbc7d8490cce..08cd7bd9d7993595dc5f896f1c3d934e8f4865b1 100644 --- a/src/main/java/org/nrg/xnat/daos/HostInfoDAO.java +++ b/src/main/java/org/nrg/xnat/daos/HostInfoDAO.java @@ -13,6 +13,13 @@ import org.springframework.transaction.annotation.Transactional; @Repository public class HostInfoDAO extends AbstractHibernateDAO<HostInfo> { + /** + * Gets the host number. + * + * @param hostName the host name + * @param setValue the set value + * @return the host number + */ @Transactional public String getHostNumber(String hostName, boolean setValue) { Criteria criteria = getCriteriaForType(); diff --git a/src/main/java/org/nrg/xnat/entities/HostInfo.java b/src/main/java/org/nrg/xnat/entities/HostInfo.java index 40f25fb44046fedfc084bc94fcaef5980eea3ac9..03529274e0b950df2164d37d5aacbf7b57ee108b 100644 --- a/src/main/java/org/nrg/xnat/entities/HostInfo.java +++ b/src/main/java/org/nrg/xnat/entities/HostInfo.java @@ -8,33 +8,50 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.UniqueConstraint; +/** + * The Class HostInfo. + */ @Entity @Table(uniqueConstraints = @UniqueConstraint(columnNames = {"hostName"})) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "nrg") public class HostInfo extends AbstractHibernateEntity { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = -1264374836830855705L; + /** The host name. */ private String hostName; + /** + * Instantiates a new host info. + */ public HostInfo() { super(); } + /** + * Instantiates a new host info. + * + * @param hostName the host name + */ public HostInfo(String hostName) { super(); this.hostName = hostName; } /** - * @param name Sets the hostname property. + * Sets the host name. + * + * @param hostName the new host name */ public void setHostName(String hostName) { this.hostName = hostName; } /** - * @return Returns the name property. + * Gets the host name. + * + * @return the host name */ public String getHostName() { return this.hostName; diff --git a/src/main/java/org/nrg/xnat/services/impl/hibernate/HibernateHostInfoService.java b/src/main/java/org/nrg/xnat/services/impl/hibernate/HibernateHostInfoService.java index 4c2fab75593e366664cee1683bcede5f6dec5129..d97bfdb2a1973b24913a799d3819df08d519b255 100644 --- a/src/main/java/org/nrg/xnat/services/impl/hibernate/HibernateHostInfoService.java +++ b/src/main/java/org/nrg/xnat/services/impl/hibernate/HibernateHostInfoService.java @@ -1,3 +1,6 @@ +/* + * + */ package org.nrg.xnat.services.impl.hibernate; import org.nrg.framework.orm.hibernate.AbstractHibernateEntityService; @@ -7,15 +10,27 @@ import org.nrg.xnat.entities.HostInfo; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +/** + * The Class HibernateHostInfoService. + */ @Service public class HibernateHostInfoService extends AbstractHibernateEntityService<HostInfo, HostInfoDAO> { + /** The _instance. */ private static HibernateHostInfoService _instance; + /** + * Instantiates a new hibernate host info service. + */ public HibernateHostInfoService() { _instance = this; } + /** + * Gets the service. + * + * @return the service + */ public static HibernateHostInfoService getService() { if (_instance == null) { _instance = XDAT.getContextService().getBean(HibernateHostInfoService.class); @@ -23,11 +38,22 @@ public class HibernateHostInfoService extends AbstractHibernateEntityService<Hos return _instance; } + /** + * Gets the host number. + * + * @return the host number + */ @Transactional public String getHostNumber() { return getDao().getHostNumber(); } + /** + * Gets the host number. + * + * @param hostName the host name + * @return the host number + */ @Transactional public String getHostNumber(String hostName) { return getDao().getHostNumber(hostName); diff --git a/src/main/java/org/nrg/xnat/turbine/utils/IDGenerator.java b/src/main/java/org/nrg/xnat/turbine/utils/IDGenerator.java index 5c4c3039277a3acd73b260e527136323acc37c48..2dc7ce1ba84753b3524259743ad5f9eab4e177b8 100644 --- a/src/main/java/org/nrg/xnat/turbine/utils/IDGenerator.java +++ b/src/main/java/org/nrg/xnat/turbine/utils/IDGenerator.java @@ -1,12 +1,12 @@ /* * org.nrg.xnat.turbine.utils.IDGenerator * XNAT http://www.xnat.org - * Copyright (c) 2014, Washington University School of Medicine + * Copyright (c) 2016, Washington University School of Medicine * All Rights Reserved * * Released under the Simplified BSD. * - * Last modified 7/10/13 9:04 PM + * Last modified 3/2/16 3:04 PM */ package org.nrg.xnat.turbine.utils; @@ -14,34 +14,37 @@ import org.nrg.xft.XFT; import org.nrg.xft.XFTTable; import org.nrg.xft.identifier.IDGeneratorI; import org.nrg.xft.utils.StringUtils; -import org.nrg.xnat.daos.HostInfoDAO; import org.nrg.xnat.services.impl.hibernate.HibernateHostInfoService; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +// TODO: Auto-generated Javadoc +/** + * The Class IDGenerator. + */ public class IDGenerator implements IDGeneratorI { + + /** The column. */ String column=null; + + /** The table name. */ String tableName=null; + + /** The digits. */ Integer digits=null; + + /** The code. */ String code=null; - private static String site_id=null; - private static String hostInfo=null; - private static String getSiteID(){ - if(site_id==null){ - site_id = XFT.GetSiteID(); - site_id = StringUtils.ReplaceStr(site_id, " ", ""); - site_id = StringUtils.ReplaceStr(site_id, "-", "_"); - site_id = StringUtils.ReplaceStr(site_id, "\"", ""); - site_id = StringUtils.ReplaceStr(site_id, "'", ""); - site_id = StringUtils.ReplaceStr(site_id, "^", ""); - } - return site_id; - } + /** The host info. */ + private static String hostInfo=null; + /** + * Gets the host info. + * + * @return the host info + */ private static String getHostInfo(){ if (hostInfo==null || hostInfo.isEmpty()) { hostInfo = HibernateHostInfoService.getService().getHostNumber(); @@ -49,13 +52,18 @@ public class IDGenerator implements IDGeneratorI { return hostInfo; } + /** The claimed i ds. */ private static List<String> claimedIDs=new ArrayList<String>(); + /** The Constant lock. */ private static final Object lock=new Object(); + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#generateIdentifier() + */ public String generateIdentifier() throws Exception{ synchronized (lock){ - String site= IDGenerator.getSiteID(); + String site= getSiteID(); String hostInfo = IDGenerator.getHostInfo(); // Let's keep the usual ID for the main server and append the host information for shadow/secondary servers if (Integer.valueOf(hostInfo)>1) { @@ -100,36 +108,76 @@ public class IDGenerator implements IDGeneratorI { } } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#getColumn() + */ public String getColumn() { return column; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#getDigits() + */ public Integer getDigits() { return digits; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#getTable() + */ public String getTable() { return tableName; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#setColumn(java.lang.String) + */ public void setColumn(String s) { this.column=s; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#setDigits(java.lang.Integer) + */ public void setDigits(Integer i) { this.digits=i; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#setTable(java.lang.String) + */ public void setTable(String s) { this.tableName=s; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#getCode() + */ public String getCode() { return code; } + /* (non-Javadoc) + * @see org.nrg.xft.identifier.IDGeneratorI#setCode(java.lang.String) + */ public void setCode(String s) { this.code=s; } + + /** + * Gets the site id. + * + * @return the site id + */ + private String getSiteID(){ + String site_id = XFT.GetSiteID(); + site_id = StringUtils.ReplaceStr(site_id, " ", ""); + site_id = StringUtils.ReplaceStr(site_id, "-", "_"); + site_id = StringUtils.ReplaceStr(site_id, "\"", ""); + site_id = StringUtils.ReplaceStr(site_id, "'", ""); + site_id = StringUtils.ReplaceStr(site_id, "^", ""); + return site_id; + } + }