package org.yeastrc.proxl.import_xml_to_db.process_input;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.yeastrc.proxl.import_xml_to_db.objects.PerPeptideData;
import org.yeastrc.proxl_import.api.xml_dto.Modification;
import org.yeastrc.proxl_import.api.xml_dto.Modifications;
import org.yeastrc.proxl_import.api.xml_dto.Peptide;
import org.yeastrc.xlink.dao.PeptideDAO;
import org.yeastrc.xlink.dto.DynamicModDTO;
import org.yeastrc.xlink.dto.MatchedPeptideDTO;
import org.yeastrc.xlink.dto.PeptideDTO;

/**
 * 
 *
 */
public class GetPerPeptideData {

	private static final Logger log = Logger.getLogger(GetPerPeptideData.class);

	private GetPerPeptideData() { }
	public static GetPerPeptideData getInstance() { return new GetPerPeptideData(); }
	

	/**
	 * @param peptide
	 * @return
	 * @throws Exception 
	 */
	public PerPeptideData getPerPeptideData( Peptide peptide, int nrseqDatabaseId ) throws Exception {
		
		PerPeptideData perPeptideData = new PerPeptideData();
		
		//  Add the peptide sequence if not in DB, otherwise retrieve existing record.
		PeptideDTO peptideDTO = PeptideDAO.getInstance().getPeptideDTO( peptide.getSequence() );

		perPeptideData.setPeptideDTO( peptideDTO );
		
		MatchedPeptideDTO matchedPeptideDTO = new MatchedPeptideDTO();
		perPeptideData.setMatchedPeptideDTO( matchedPeptideDTO );
		matchedPeptideDTO.setPeptide_id( peptideDTO.getId() );
		

		List<DynamicModDTO> dynamicModDTOList_Peptide = new ArrayList<>();
		List<Integer> monolinkPositionList = new ArrayList<>();

		perPeptideData.setDynamicModDTOList_Peptide( dynamicModDTOList_Peptide );
		perPeptideData.setMonolinkPositionList( monolinkPositionList );

		Modifications modifications = peptide.getModifications();
		
		if ( modifications != null ) {

			List<Modification> modificationList = modifications.getModification();

			if ( modificationList != null ) {

				for ( Modification modification : modificationList ) {

					int position = modification.getPosition().intValue();
					BigDecimal mass = modification.getMass();
					boolean monolink = modification.isIsMonolink();

					DynamicModDTO dynamicModDTO = new DynamicModDTO();
					dynamicModDTO.setPosition( position );
					dynamicModDTO.setMass( mass.doubleValue() );
					dynamicModDTOList_Peptide.add( dynamicModDTO );

					if ( monolink ) {

						monolinkPositionList.add( position );
					}
				}
			}
		}
		
		return perPeptideData;
	}
	
}

@@ -129,24 +129,26 @@
 util.List;%0A%0A
+//
 import org.a
@@ -167,16 +167,18 @@
 Logger;%0A
+%0A%0A
 import o
@@ -629,16 +629,18 @@
 Data %7B%0A%0A
+//
 %09private
@@ -2115,17 +2115,17 @@
 );%0A%09%09%09%09%09
-b
+B
 oolean m
@@ -2387,19 +2387,87 @@
 onolink 
-) %7B
+!= null && monolink ) %7B%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09dynamicModDTO.setMonolink( true );
 %0A%0A%09%09%09%09%09%09

Set is_monolink in dynamic_mod table