Changeset 4432


Ignore:
Timestamp:
Mar 7, 2013, 3:35:16 PM (10 years ago)
Author:
Fredrik Levander
Message:

Refs #800. Added core function for removing biomaterial from file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/api/core/src/org/proteios/core/File.java

    r4345 r4432  
    446446
    447447
    448   /**
    449    * Add a BioMaterial
    450    *
    451    * @param bioMaterial The BioMaterial to add to the Set
    452    */
    453   @SuppressWarnings("unchecked")
    454   public void addBioMaterial(BioMaterial bioMaterial)
    455   {
    456     ((BioMaterialData) bioMaterial.getData()).getFiles()
    457       .add(this.getData());
    458     getData().getBioMaterials()
    459       .add((BioMaterialData) bioMaterial.getData());
    460   }
    461 
    462 
    463   /**
    464    * @return Returns the bioMaterials.
    465    */
    466   @SuppressWarnings("unchecked")
    467   public Set<BioMaterial> getBioMaterials()
    468       throws ItemNotFoundException, BaseException
    469   {
    470     Set<BioMaterial> bioMaterials = new HashSet<BioMaterial>();
    471     try
    472     {
    473       Iterator<BioMaterialData> it = getData().getBioMaterials()
    474         .iterator();
    475       while (it.hasNext())
    476       {
    477         bioMaterials.add(getDbControl().getItem(BioMaterial.class,
    478           it.next()));
    479       }
    480     }
    481     catch (org.hibernate.ObjectNotFoundException e)
    482     {
    483       throw new ItemNotFoundException(HibernateUtil.getShortEntityName(e
    484         .getEntityName()) + "[id=" + e.getIdentifier() + "]");
    485     }
    486     return bioMaterials;
    487   }
    488 
    489 
    490   /**
    491    * Set the {@link BioMaterial} bioMaterials set.
    492    *
    493    * @param bioMaterials The new <code>Set<BioMaterial></code> item.
    494    */
    495   @SuppressWarnings("unchecked")
    496   public void setBioMaterials(Set<BioMaterial> bioMaterials)
    497   {
    498     Set<BioMaterialData> bmData = new HashSet<BioMaterialData>();
    499     Iterator<BioMaterial> it = bioMaterials.iterator();
    500     while (it.hasNext())
    501     {
    502       bmData.add((BioMaterialData) it.next().getData());
    503     }
    504     getData().setBioMaterials(bmData);
    505   }
    506 
     448   /**
     449     * Add a BioMaterial
     450     *
     451     * @param bioMaterial The BioMaterial to add to the Set
     452     */
     453    public void addBioMaterial(BioMaterial<?> bioMaterial)
     454    {
     455        ((BioMaterialData) bioMaterial.getData()).getFiles()
     456            .add(this.getData());
     457        getData().getBioMaterials()
     458            .add((BioMaterialData) bioMaterial.getData());
     459    }
     460
     461
     462    /**
     463     * Remove a BioMaterial
     464     *
     465     * @param bioMaterial The BioMaterial to remove from the Set
     466     */
     467    public void removeBioMaterial(BioMaterial<?> bioMaterial)
     468    {
     469        if (bioMaterial != null)
     470        {
     471            ((BioMaterialData) bioMaterial.getData()).getFiles().remove(
     472                this.getData());
     473            getData().getBioMaterials().remove(
     474                (BioMaterialData) bioMaterial.getData());
     475        }
     476    }
     477
     478
     479    /**
     480     * @return Returns the bioMaterials.
     481     */
     482    public Set<BioMaterial> getBioMaterials()
     483            throws ItemNotFoundException, BaseException
     484    {
     485        Set<BioMaterial> bioMaterials = new HashSet<BioMaterial>();
     486        try
     487        {
     488            Iterator<BioMaterialData> it = getData().getBioMaterials()
     489                .iterator();
     490            while (it.hasNext())
     491            {
     492 bioMaterials.add(getDbControl().getItem(BioMaterial.class,
     493                    it.next()));
     494            }
     495        }
     496        catch (org.hibernate.ObjectNotFoundException e)
     497        {
     498            throw new ItemNotFoundException(HibernateUtil.getShortEntityName(e
     499                .getEntityName()) + "[id=" + e.getIdentifier() + "]");
     500        }
     501        return bioMaterials;
     502    }
     503
     504
     505    /**
     506     * Set the {@link BioMaterial} bioMaterials set.
     507     *
     508     * @param bioMaterials The new <code>Set<BioMaterial></code> item.
     509     */
     510    public void setBioMaterials(Set<BioMaterial> bioMaterials)
     511    {
     512        Set<BioMaterialData> bmData = new HashSet<BioMaterialData>();
     513        Iterator<BioMaterial> it = bioMaterials.iterator();
     514        while (it.hasNext())
     515        {
     516            bmData.add((BioMaterialData) it.next().getData());
     517        }
     518        getData().setBioMaterials(bmData);
     519    }
    507520
    508521  // -------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.