repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/OfficeClass.java | // Path: src/main/java/org/votesmart/data/Branches.java
// @XmlRootElement(name="branches")
// public class Branches extends GeneralInfoBase {
//
// public ArrayList<Branch> branch;
//
// @XmlType(name="branch", namespace="branches")
// public static class Branch {
// public String officeBranchId;
// public String name;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/Levels.java
// @XmlRootElement(name="levels")
// public class Levels extends GeneralInfoBase {
//
// public ArrayList<Level> level;
//
// @XmlType(name="level", namespace="levels")
// public static class Level {
// public String officeLevelId;
// public String name;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/OfficeTypes.java
// @XmlRootElement(name="officeTypes")
// public class OfficeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="office")
// public static class Type {
// public String officeTypeId;
// public String officeLevelId;
// public String officeBranchId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Offices.java
// @XmlRootElement(name="offices")
// public class Offices extends GeneralInfoBase {
// public ArrayList<Office> office;
//
// @XmlType(name="office", namespace="offices")
// public static class Office {
// public String officeId;
// public String officeTypeId;
// public String officeLevelId;
// public String officeBranchId;
// public String name;
// public String title;
// public String shortTitle;
// }
//
// }
| import org.votesmart.api.*;
import org.votesmart.data.Branches;
import org.votesmart.data.Levels;
import org.votesmart.data.OfficeTypes;
import org.votesmart.data.Offices;
| package org.votesmart.classes;
/**
* <pre>
* Office Class
*
* Office.getTypes
* This method dumps all office types we keep track of
* Input: none
* Output: {@link OfficeTypes}
*
* Office.getBranches
* This method dumps the branches of government and their IDs
* Input: none
* Output: {@link Branches}
*
* Office.getLevels
* This method dumps the levels of government and their IDs
* Input: none
* Output: {@link Levels}
*
* Office.getOfficesByType
* This method dumps offices we keep track of according to type.
* Input: officeTypeId*
* Output: {@link Offices}
*
* Office.getOfficesByLevel
* This method dumps offices we keep track of according to level.
* Input: levelId*
* Output: {@link Offices}
*
* Office.getOfficesByTypeLevel
* This method dumps offices we keep track of according to type and level.
* Input: officeTypeId*, levelId*
* Output: {@link Offices}
*
* Office.getOfficesByBranchLevel
* This method dumps offices we keep track of according to branch and level.
* Input: branchId*, levelId*
* Output: {@link Offices}
*
* ============== EXAMPLE USAGE ============
*
* // Get general Information about offices
* OfficeClass officeClass = new OfficeClass();
*
* // get Office.getBranches
* Branches branches = officeClass.getBranches();
* Branches.Branch officeBranch = branches.branch.get(1);
*
* // Office.getTypes
* OfficeTypes officeTypes = officeClass.getTypes();
* OfficeTypes.Type officeType = officeTypes.type.get(5);
*
* // Office.getLevels
* Levels levels = officeClass.getLevels();
* Levels.Level officeLevel = levels.level.get(1);
* </pre>
*
*/
public class OfficeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public OfficeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public OfficeClass() throws VoteSmartException {
super();
}
/**
* This method dumps all office types we keep track of.
*
* @return {@link OfficeTypes}:
*/
public OfficeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Office.getTypes", null, OfficeTypes.class );
}
/**
* This method dumps the branches of government and their IDs.
*
* @return {@link Branches}:
*/
public Branches getBranches() throws VoteSmartException, VoteSmartErrorException {
return api.query("Office.getBranches", null, Branches.class );
}
/**
* This method dumps the levels of government and their IDs.
*
* @return {@link Levels}:
*/
public Levels getLevels() throws VoteSmartException, VoteSmartErrorException {
return api.query("Office.getLevels", null, Levels.class );
}
/**
* This method dumps offices we keep track of according to type.
*
* @param officeTypeId
* @return {@link Offices}:
*/
| // Path: src/main/java/org/votesmart/data/Branches.java
// @XmlRootElement(name="branches")
// public class Branches extends GeneralInfoBase {
//
// public ArrayList<Branch> branch;
//
// @XmlType(name="branch", namespace="branches")
// public static class Branch {
// public String officeBranchId;
// public String name;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/Levels.java
// @XmlRootElement(name="levels")
// public class Levels extends GeneralInfoBase {
//
// public ArrayList<Level> level;
//
// @XmlType(name="level", namespace="levels")
// public static class Level {
// public String officeLevelId;
// public String name;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/OfficeTypes.java
// @XmlRootElement(name="officeTypes")
// public class OfficeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="office")
// public static class Type {
// public String officeTypeId;
// public String officeLevelId;
// public String officeBranchId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Offices.java
// @XmlRootElement(name="offices")
// public class Offices extends GeneralInfoBase {
// public ArrayList<Office> office;
//
// @XmlType(name="office", namespace="offices")
// public static class Office {
// public String officeId;
// public String officeTypeId;
// public String officeLevelId;
// public String officeBranchId;
// public String name;
// public String title;
// public String shortTitle;
// }
//
// }
// Path: src/main/java/org/votesmart/classes/OfficeClass.java
import org.votesmart.api.*;
import org.votesmart.data.Branches;
import org.votesmart.data.Levels;
import org.votesmart.data.OfficeTypes;
import org.votesmart.data.Offices;
package org.votesmart.classes;
/**
* <pre>
* Office Class
*
* Office.getTypes
* This method dumps all office types we keep track of
* Input: none
* Output: {@link OfficeTypes}
*
* Office.getBranches
* This method dumps the branches of government and their IDs
* Input: none
* Output: {@link Branches}
*
* Office.getLevels
* This method dumps the levels of government and their IDs
* Input: none
* Output: {@link Levels}
*
* Office.getOfficesByType
* This method dumps offices we keep track of according to type.
* Input: officeTypeId*
* Output: {@link Offices}
*
* Office.getOfficesByLevel
* This method dumps offices we keep track of according to level.
* Input: levelId*
* Output: {@link Offices}
*
* Office.getOfficesByTypeLevel
* This method dumps offices we keep track of according to type and level.
* Input: officeTypeId*, levelId*
* Output: {@link Offices}
*
* Office.getOfficesByBranchLevel
* This method dumps offices we keep track of according to branch and level.
* Input: branchId*, levelId*
* Output: {@link Offices}
*
* ============== EXAMPLE USAGE ============
*
* // Get general Information about offices
* OfficeClass officeClass = new OfficeClass();
*
* // get Office.getBranches
* Branches branches = officeClass.getBranches();
* Branches.Branch officeBranch = branches.branch.get(1);
*
* // Office.getTypes
* OfficeTypes officeTypes = officeClass.getTypes();
* OfficeTypes.Type officeType = officeTypes.type.get(5);
*
* // Office.getLevels
* Levels levels = officeClass.getLevels();
* Levels.Level officeLevel = levels.level.get(1);
* </pre>
*
*/
public class OfficeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public OfficeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public OfficeClass() throws VoteSmartException {
super();
}
/**
* This method dumps all office types we keep track of.
*
* @return {@link OfficeTypes}:
*/
public OfficeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Office.getTypes", null, OfficeTypes.class );
}
/**
* This method dumps the branches of government and their IDs.
*
* @return {@link Branches}:
*/
public Branches getBranches() throws VoteSmartException, VoteSmartErrorException {
return api.query("Office.getBranches", null, Branches.class );
}
/**
* This method dumps the levels of government and their IDs.
*
* @return {@link Levels}:
*/
public Levels getLevels() throws VoteSmartException, VoteSmartErrorException {
return api.query("Office.getLevels", null, Levels.class );
}
/**
* This method dumps offices we keep track of according to type.
*
* @param officeTypeId
* @return {@link Offices}:
*/
| public Offices getOfficesByType(String officeTypeId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/NpatClass.java | // Path: src/main/java/org/votesmart/data/Npat.java
// @XmlRootElement(name="npat")
// public class Npat extends GeneralInfoBase {
// public String candidateId;
// public String candidate;
// public String passed;
// public String npatName;
// public String electionName;
// public String electionYear;
// public String electionDate;
// public String electionStage;
// public String surveyMessage;
// public ArrayList<Section> section;
//
// @XmlType(name="section", namespace="npat")
// public static class Section {
// public String name;
// public ArrayList<Row> row;
//
// @XmlType(name="row", namespace="npat.section")
// public static class Row {
// public String path;
// public String rowText;
// public String rowType;
// public String open;
// public String optionText;
// public String answerText;
// public ArrayList<Row> row;
// }
// }
//
// }
| import org.votesmart.api.*;
import org.votesmart.data.Npat;
| package org.votesmart.classes;
/**
* <pre>
* NPAT/PCT Class
* * - Required
* * - Multiple rows
* * - Possibly Recursive
*
* Npat.getNpat()
* This method returns the candidates most recently filled out NPAT/PCT.
* NOTE: This is the only class that responds with recursive data.
* Input: candidateId*
* Output: {@link Npat}
*
* ========== EXAMPLE USAGE =============
*
* // Npat class
* NpatClass npatClass = new NpatClass();
*
* // Npat if it exists
* Npat npat = npatClass.getNpat(leader.candidateId);
* </pre>
*
*/
public class NpatClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public NpatClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public NpatClass() throws VoteSmartException {
super();
}
/**
* This method returns the candidates most recently filled out NPAT/PCT.
* NOTE: This is the only class that responds with recursive data.
*
* @param candidateId
* @return {@link Npat}:
*/
| // Path: src/main/java/org/votesmart/data/Npat.java
// @XmlRootElement(name="npat")
// public class Npat extends GeneralInfoBase {
// public String candidateId;
// public String candidate;
// public String passed;
// public String npatName;
// public String electionName;
// public String electionYear;
// public String electionDate;
// public String electionStage;
// public String surveyMessage;
// public ArrayList<Section> section;
//
// @XmlType(name="section", namespace="npat")
// public static class Section {
// public String name;
// public ArrayList<Row> row;
//
// @XmlType(name="row", namespace="npat.section")
// public static class Row {
// public String path;
// public String rowText;
// public String rowType;
// public String open;
// public String optionText;
// public String answerText;
// public ArrayList<Row> row;
// }
// }
//
// }
// Path: src/main/java/org/votesmart/classes/NpatClass.java
import org.votesmart.api.*;
import org.votesmart.data.Npat;
package org.votesmart.classes;
/**
* <pre>
* NPAT/PCT Class
* * - Required
* * - Multiple rows
* * - Possibly Recursive
*
* Npat.getNpat()
* This method returns the candidates most recently filled out NPAT/PCT.
* NOTE: This is the only class that responds with recursive data.
* Input: candidateId*
* Output: {@link Npat}
*
* ========== EXAMPLE USAGE =============
*
* // Npat class
* NpatClass npatClass = new NpatClass();
*
* // Npat if it exists
* Npat npat = npatClass.getNpat(leader.candidateId);
* </pre>
*
*/
public class NpatClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public NpatClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public NpatClass() throws VoteSmartException {
super();
}
/**
* This method returns the candidates most recently filled out NPAT/PCT.
* NOTE: This is the only class that responds with recursive data.
*
* @param candidateId
* @return {@link Npat}:
*/
| public Npat getNpat(String candidateId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/DistrictClass.java | // Path: src/main/java/org/votesmart/data/DistrictList.java
// @XmlRootElement(name="districtList")
// public class DistrictList extends GeneralInfoBase {
// public String zipMessage;
// public ArrayList<District> district;
// public ArrayList<District> electionDistricts;
//
// @XmlType(name="district", namespace="districtList")
// public static class District {
// public String districtId;
// public String name;
// public String officeId;
// public String stateId;
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.DistrictList;
| package org.votesmart.classes;
/**
* <pre>
* District Class
*
* District.getByOfficeState()
* This method grabs district IDs according to the office and state.
* Input: officeId*, stateId*, districtName(Default: Null)
* Output: {@link DistrictList}
*
* District.getByZip()
* This method grabs district IDs according to the zip code.
* Input: zip5*, zip4 (Default: Null)
* Output: {@link DistrictList}
*
* ============= EXAMPLE USAGE ===================
*
* DistrictClass districtClass = new DistrictClass();
*
* DistrictList districtList = districtClass.getByOfficeState(office.officeId, state.stateId);
* DistrictList.District district = districtList.district.get(0);
*
* </pre>
*
*/
public class DistrictClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public DistrictClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public DistrictClass() throws VoteSmartException {
super();
}
/**
* This method grabs district IDs according to the office and state.
*
* @param officeId
* @param stateId
* @return {@link DistrictList}:
*/
| // Path: src/main/java/org/votesmart/data/DistrictList.java
// @XmlRootElement(name="districtList")
// public class DistrictList extends GeneralInfoBase {
// public String zipMessage;
// public ArrayList<District> district;
// public ArrayList<District> electionDistricts;
//
// @XmlType(name="district", namespace="districtList")
// public static class District {
// public String districtId;
// public String name;
// public String officeId;
// public String stateId;
// }
// }
// Path: src/main/java/org/votesmart/classes/DistrictClass.java
import org.votesmart.api.*;
import org.votesmart.data.DistrictList;
package org.votesmart.classes;
/**
* <pre>
* District Class
*
* District.getByOfficeState()
* This method grabs district IDs according to the office and state.
* Input: officeId*, stateId*, districtName(Default: Null)
* Output: {@link DistrictList}
*
* District.getByZip()
* This method grabs district IDs according to the zip code.
* Input: zip5*, zip4 (Default: Null)
* Output: {@link DistrictList}
*
* ============= EXAMPLE USAGE ===================
*
* DistrictClass districtClass = new DistrictClass();
*
* DistrictList districtList = districtClass.getByOfficeState(office.officeId, state.stateId);
* DistrictList.District district = districtList.district.get(0);
*
* </pre>
*
*/
public class DistrictClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public DistrictClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public DistrictClass() throws VoteSmartException {
super();
}
/**
* This method grabs district IDs according to the office and state.
*
* @param officeId
* @param stateId
* @return {@link DistrictList}:
*/
| public DistrictList getByOfficeState( String officeId, String stateId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/AddressClass.java | // Path: src/main/java/org/votesmart/data/AddressAddress.java
// @XmlRootElement(name="address")
// public class AddressAddress extends GeneralInfoBase {
//
// public ArrayList<Office> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/AddressOffice.java
// @XmlRootElement(name="address")
// public class AddressOffice extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<OfficeAddress> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/WebAddress.java
// @XmlRootElement(name="webaddress")
// public class WebAddress extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<Address> address;
//
// @XmlType(name="address", namespace="webaddress")
// public static class Address {
// public String webAddressTypeId;
// public String webAddressType;
// public String webAddress;
// }
//
// }
| import org.votesmart.api.*;
import org.votesmart.data.AddressAddress;
import org.votesmart.data.AddressOffice;
import org.votesmart.data.WebAddress;
| package org.votesmart.classes;
/**
* <pre>
* Address Class
* * - Required
* * - Multiple rows
*
* Address.getCampaign
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getCampaignWebAddress
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getCampaignByElection
* This method grabs campaign office(s) and basic candidate information for the specified election.
* Input: electionId*
* Output: {@link AddressOffice}
*
* Address.getOffice
* This method grabs office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getOfficeWebAddress
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getOfficeByOfficeState
* This method grabs office address and basic candidate information according to the officeId and state.
* Input: officeId*, stateId (Default: 'NA')
* Output: {@link AddressAddress}
*
* ==== EXAMPLE USAGE =====
*
* AddressClass addressClass = new AddressClass();
*
* // address of Office (State Assembly)
* AddressAddress addressOffice = addressClass.getOfficeByOfficeState(office.officeId, state.stateId);
*
* // address of Official
* AddressOffice addressOffical = addressClass.getOffice(candidate.candidateId)
*
* // WebAddress of Official
* WebAddress webAddressOffical = addressClass.getOfficeWebAddress(candidate.candidateId);
*</pre>
*/
public class AddressClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public AddressClass(VoteSmartAPI api) {
super(api);
}
/**
* Default constructor
*/
public AddressClass() throws VoteSmartException {
super();
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: address and list of office addresses.
*/
| // Path: src/main/java/org/votesmart/data/AddressAddress.java
// @XmlRootElement(name="address")
// public class AddressAddress extends GeneralInfoBase {
//
// public ArrayList<Office> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/AddressOffice.java
// @XmlRootElement(name="address")
// public class AddressOffice extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<OfficeAddress> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/WebAddress.java
// @XmlRootElement(name="webaddress")
// public class WebAddress extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<Address> address;
//
// @XmlType(name="address", namespace="webaddress")
// public static class Address {
// public String webAddressTypeId;
// public String webAddressType;
// public String webAddress;
// }
//
// }
// Path: src/main/java/org/votesmart/classes/AddressClass.java
import org.votesmart.api.*;
import org.votesmart.data.AddressAddress;
import org.votesmart.data.AddressOffice;
import org.votesmart.data.WebAddress;
package org.votesmart.classes;
/**
* <pre>
* Address Class
* * - Required
* * - Multiple rows
*
* Address.getCampaign
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getCampaignWebAddress
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getCampaignByElection
* This method grabs campaign office(s) and basic candidate information for the specified election.
* Input: electionId*
* Output: {@link AddressOffice}
*
* Address.getOffice
* This method grabs office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getOfficeWebAddress
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getOfficeByOfficeState
* This method grabs office address and basic candidate information according to the officeId and state.
* Input: officeId*, stateId (Default: 'NA')
* Output: {@link AddressAddress}
*
* ==== EXAMPLE USAGE =====
*
* AddressClass addressClass = new AddressClass();
*
* // address of Office (State Assembly)
* AddressAddress addressOffice = addressClass.getOfficeByOfficeState(office.officeId, state.stateId);
*
* // address of Official
* AddressOffice addressOffical = addressClass.getOffice(candidate.candidateId)
*
* // WebAddress of Official
* WebAddress webAddressOffical = addressClass.getOfficeWebAddress(candidate.candidateId);
*</pre>
*/
public class AddressClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public AddressClass(VoteSmartAPI api) {
super(api);
}
/**
* Default constructor
*/
public AddressClass() throws VoteSmartException {
super();
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: address and list of office addresses.
*/
| public AddressOffice getCampaign(String candidateId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/AddressClass.java | // Path: src/main/java/org/votesmart/data/AddressAddress.java
// @XmlRootElement(name="address")
// public class AddressAddress extends GeneralInfoBase {
//
// public ArrayList<Office> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/AddressOffice.java
// @XmlRootElement(name="address")
// public class AddressOffice extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<OfficeAddress> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/WebAddress.java
// @XmlRootElement(name="webaddress")
// public class WebAddress extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<Address> address;
//
// @XmlType(name="address", namespace="webaddress")
// public static class Address {
// public String webAddressTypeId;
// public String webAddressType;
// public String webAddress;
// }
//
// }
| import org.votesmart.api.*;
import org.votesmart.data.AddressAddress;
import org.votesmart.data.AddressOffice;
import org.votesmart.data.WebAddress;
| package org.votesmart.classes;
/**
* <pre>
* Address Class
* * - Required
* * - Multiple rows
*
* Address.getCampaign
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getCampaignWebAddress
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getCampaignByElection
* This method grabs campaign office(s) and basic candidate information for the specified election.
* Input: electionId*
* Output: {@link AddressOffice}
*
* Address.getOffice
* This method grabs office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getOfficeWebAddress
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getOfficeByOfficeState
* This method grabs office address and basic candidate information according to the officeId and state.
* Input: officeId*, stateId (Default: 'NA')
* Output: {@link AddressAddress}
*
* ==== EXAMPLE USAGE =====
*
* AddressClass addressClass = new AddressClass();
*
* // address of Office (State Assembly)
* AddressAddress addressOffice = addressClass.getOfficeByOfficeState(office.officeId, state.stateId);
*
* // address of Official
* AddressOffice addressOffical = addressClass.getOffice(candidate.candidateId)
*
* // WebAddress of Official
* WebAddress webAddressOffical = addressClass.getOfficeWebAddress(candidate.candidateId);
*</pre>
*/
public class AddressClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public AddressClass(VoteSmartAPI api) {
super(api);
}
/**
* Default constructor
*/
public AddressClass() throws VoteSmartException {
super();
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: address and list of office addresses.
*/
public AddressOffice getCampaign(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaign", new ArgMap("candidateId", candidateId), AddressOffice.class );
}
/**
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link WebAddress}: Candidate name and URL's
*/
| // Path: src/main/java/org/votesmart/data/AddressAddress.java
// @XmlRootElement(name="address")
// public class AddressAddress extends GeneralInfoBase {
//
// public ArrayList<Office> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/AddressOffice.java
// @XmlRootElement(name="address")
// public class AddressOffice extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<OfficeAddress> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/WebAddress.java
// @XmlRootElement(name="webaddress")
// public class WebAddress extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<Address> address;
//
// @XmlType(name="address", namespace="webaddress")
// public static class Address {
// public String webAddressTypeId;
// public String webAddressType;
// public String webAddress;
// }
//
// }
// Path: src/main/java/org/votesmart/classes/AddressClass.java
import org.votesmart.api.*;
import org.votesmart.data.AddressAddress;
import org.votesmart.data.AddressOffice;
import org.votesmart.data.WebAddress;
package org.votesmart.classes;
/**
* <pre>
* Address Class
* * - Required
* * - Multiple rows
*
* Address.getCampaign
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getCampaignWebAddress
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getCampaignByElection
* This method grabs campaign office(s) and basic candidate information for the specified election.
* Input: electionId*
* Output: {@link AddressOffice}
*
* Address.getOffice
* This method grabs office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getOfficeWebAddress
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getOfficeByOfficeState
* This method grabs office address and basic candidate information according to the officeId and state.
* Input: officeId*, stateId (Default: 'NA')
* Output: {@link AddressAddress}
*
* ==== EXAMPLE USAGE =====
*
* AddressClass addressClass = new AddressClass();
*
* // address of Office (State Assembly)
* AddressAddress addressOffice = addressClass.getOfficeByOfficeState(office.officeId, state.stateId);
*
* // address of Official
* AddressOffice addressOffical = addressClass.getOffice(candidate.candidateId)
*
* // WebAddress of Official
* WebAddress webAddressOffical = addressClass.getOfficeWebAddress(candidate.candidateId);
*</pre>
*/
public class AddressClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public AddressClass(VoteSmartAPI api) {
super(api);
}
/**
* Default constructor
*/
public AddressClass() throws VoteSmartException {
super();
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: address and list of office addresses.
*/
public AddressOffice getCampaign(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaign", new ArgMap("candidateId", candidateId), AddressOffice.class );
}
/**
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link WebAddress}: Candidate name and URL's
*/
| public WebAddress getCampaignWebAddress(String candidateId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/AddressClass.java | // Path: src/main/java/org/votesmart/data/AddressAddress.java
// @XmlRootElement(name="address")
// public class AddressAddress extends GeneralInfoBase {
//
// public ArrayList<Office> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/AddressOffice.java
// @XmlRootElement(name="address")
// public class AddressOffice extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<OfficeAddress> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/WebAddress.java
// @XmlRootElement(name="webaddress")
// public class WebAddress extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<Address> address;
//
// @XmlType(name="address", namespace="webaddress")
// public static class Address {
// public String webAddressTypeId;
// public String webAddressType;
// public String webAddress;
// }
//
// }
| import org.votesmart.api.*;
import org.votesmart.data.AddressAddress;
import org.votesmart.data.AddressOffice;
import org.votesmart.data.WebAddress;
| package org.votesmart.classes;
/**
* <pre>
* Address Class
* * - Required
* * - Multiple rows
*
* Address.getCampaign
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getCampaignWebAddress
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getCampaignByElection
* This method grabs campaign office(s) and basic candidate information for the specified election.
* Input: electionId*
* Output: {@link AddressOffice}
*
* Address.getOffice
* This method grabs office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getOfficeWebAddress
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getOfficeByOfficeState
* This method grabs office address and basic candidate information according to the officeId and state.
* Input: officeId*, stateId (Default: 'NA')
* Output: {@link AddressAddress}
*
* ==== EXAMPLE USAGE =====
*
* AddressClass addressClass = new AddressClass();
*
* // address of Office (State Assembly)
* AddressAddress addressOffice = addressClass.getOfficeByOfficeState(office.officeId, state.stateId);
*
* // address of Official
* AddressOffice addressOffical = addressClass.getOffice(candidate.candidateId)
*
* // WebAddress of Official
* WebAddress webAddressOffical = addressClass.getOfficeWebAddress(candidate.candidateId);
*</pre>
*/
public class AddressClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public AddressClass(VoteSmartAPI api) {
super(api);
}
/**
* Default constructor
*/
public AddressClass() throws VoteSmartException {
super();
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: address and list of office addresses.
*/
public AddressOffice getCampaign(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaign", new ArgMap("candidateId", candidateId), AddressOffice.class );
}
/**
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link WebAddress}: Candidate name and URL's
*/
public WebAddress getCampaignWebAddress(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaignWebAddress", new ArgMap("candidateId", candidateId), WebAddress.class );
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified election.
*
* @param electionId
* @return {@link AddressOffice}: Candidate name and list of office addresses
*/
public AddressOffice getCampaignByElection(String electionId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaignByElection", new ArgMap("electionId", electionId), AddressOffice.class );
}
/**
* This method grabs office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: Candidate name and list of office addresses
*/
public AddressOffice getOffice(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getOffice", new ArgMap("candidateId", candidateId), AddressOffice.class );
}
/**
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link WebAddress}: Candidate name and list of URL's
*/
public WebAddress getOfficeWebAddress(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getOfficeWebAddress", new ArgMap("candidateId", candidateId), WebAddress.class );
}
/**
* This method grabs office address and basic candidate information according to the officeId and state.
*
* @param officeId
* @return {@link AddressAddress}: Candidate name and list of offices
*/
| // Path: src/main/java/org/votesmart/data/AddressAddress.java
// @XmlRootElement(name="address")
// public class AddressAddress extends GeneralInfoBase {
//
// public ArrayList<Office> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/AddressOffice.java
// @XmlRootElement(name="address")
// public class AddressOffice extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<OfficeAddress> office;
//
// }
//
// Path: src/main/java/org/votesmart/data/WebAddress.java
// @XmlRootElement(name="webaddress")
// public class WebAddress extends GeneralInfoBase {
//
// public CandidateMed candidate;
// public ArrayList<Address> address;
//
// @XmlType(name="address", namespace="webaddress")
// public static class Address {
// public String webAddressTypeId;
// public String webAddressType;
// public String webAddress;
// }
//
// }
// Path: src/main/java/org/votesmart/classes/AddressClass.java
import org.votesmart.api.*;
import org.votesmart.data.AddressAddress;
import org.votesmart.data.AddressOffice;
import org.votesmart.data.WebAddress;
package org.votesmart.classes;
/**
* <pre>
* Address Class
* * - Required
* * - Multiple rows
*
* Address.getCampaign
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getCampaignWebAddress
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getCampaignByElection
* This method grabs campaign office(s) and basic candidate information for the specified election.
* Input: electionId*
* Output: {@link AddressOffice}
*
* Address.getOffice
* This method grabs office(s) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link AddressOffice}
*
* Address.getOfficeWebAddress
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
* Input: candidateId*
* Output: {@link WebAddress}
*
* Address.getOfficeByOfficeState
* This method grabs office address and basic candidate information according to the officeId and state.
* Input: officeId*, stateId (Default: 'NA')
* Output: {@link AddressAddress}
*
* ==== EXAMPLE USAGE =====
*
* AddressClass addressClass = new AddressClass();
*
* // address of Office (State Assembly)
* AddressAddress addressOffice = addressClass.getOfficeByOfficeState(office.officeId, state.stateId);
*
* // address of Official
* AddressOffice addressOffical = addressClass.getOffice(candidate.candidateId)
*
* // WebAddress of Official
* WebAddress webAddressOffical = addressClass.getOfficeWebAddress(candidate.candidateId);
*</pre>
*/
public class AddressClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public AddressClass(VoteSmartAPI api) {
super(api);
}
/**
* Default constructor
*/
public AddressClass() throws VoteSmartException {
super();
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: address and list of office addresses.
*/
public AddressOffice getCampaign(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaign", new ArgMap("candidateId", candidateId), AddressOffice.class );
}
/**
* This method grabs the campaign office's Web address(es) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link WebAddress}: Candidate name and URL's
*/
public WebAddress getCampaignWebAddress(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaignWebAddress", new ArgMap("candidateId", candidateId), WebAddress.class );
}
/**
* This method grabs campaign office(s) and basic candidate information for the specified election.
*
* @param electionId
* @return {@link AddressOffice}: Candidate name and list of office addresses
*/
public AddressOffice getCampaignByElection(String electionId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getCampaignByElection", new ArgMap("electionId", electionId), AddressOffice.class );
}
/**
* This method grabs office(s) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link AddressOffice}: Candidate name and list of office addresses
*/
public AddressOffice getOffice(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getOffice", new ArgMap("candidateId", candidateId), AddressOffice.class );
}
/**
* This method grabs office's Web address(es) and basic candidate information for the specified candidate.
*
* @param candidateId
* @return {@link WebAddress}: Candidate name and list of URL's
*/
public WebAddress getOfficeWebAddress(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Address.getOfficeWebAddress", new ArgMap("candidateId", candidateId), WebAddress.class );
}
/**
* This method grabs office address and basic candidate information according to the officeId and state.
*
* @param officeId
* @return {@link AddressAddress}: Candidate name and list of offices
*/
| public AddressAddress getOfficeByOfficeState(String officeId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/CommitteeClass.java | // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
| package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
| // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
// Path: src/main/java/org/votesmart/classes/CommitteeClass.java
import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
| public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/CommitteeClass.java | // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
| package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getTypes", null, CommitteeTypes.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @return {@link Committees}:
*/
| // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
// Path: src/main/java/org/votesmart/classes/CommitteeClass.java
import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getTypes", null, CommitteeTypes.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @return {@link Committees}:
*/
| public Committees getCommitteesByTypeState() throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/CommitteeClass.java | // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
| package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getTypes", null, CommitteeTypes.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", null, Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId), Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @param stateId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId, String stateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId, "stateId", stateId), Committees.class );
}
/**
* Returns detailed committee data.
*
* @param committeeId
* @return {@link Committee}:
*/
| // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
// Path: src/main/java/org/votesmart/classes/CommitteeClass.java
import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getTypes", null, CommitteeTypes.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", null, Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId), Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @param stateId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId, String stateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId, "stateId", stateId), Committees.class );
}
/**
* Returns detailed committee data.
*
* @param committeeId
* @return {@link Committee}:
*/
| public Committee getCommittee(String committeeId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/CommitteeClass.java | // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
| package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getTypes", null, CommitteeTypes.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", null, Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId), Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @param stateId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId, String stateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId, "stateId", stateId), Committees.class );
}
/**
* Returns detailed committee data.
*
* @param committeeId
* @return {@link Committee}:
*/
public Committee getCommittee(String committeeId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommittee", new ArgMap("committeeId", committeeId), Committee.class );
}
/**
* Returns members of the committee.
*
* @param committeeId
* @return {@link CommitteeMembers}:
*/
| // Path: src/main/java/org/votesmart/data/Committee.java
// @XmlRootElement(name="committee")
// public class Committee extends GeneralInfoBase {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// public String jurisdiction;
// public Contact contact;
//
// @XmlType(name="contact", namespace="committee")
// public static class Contact {
// public String address1;
// public String address2;
// public String city;
// public String state;
// public String zip;
// public String phone;
// public String fax;
// public String email;
// public URL url;
// public String staffContact;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeMembers.java
// @XmlRootElement(name="committeeMembers")
// public class CommitteeMembers extends GeneralInfoBase {
// public Committee committee;
// public ArrayList<Member> member;
//
// @XmlType(name="commiittee", namespace="committeeMembers")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String name;
// }
// @XmlType(name="member", namespace="committeeMembers")
// public static class Member {
// public String candidateId;
// public String title;
// public String firstName;
// public String middleName;
// public String lastName;
// public String suffix;
// public String party;
// public String position;
// }
//
// }
//
// Path: src/main/java/org/votesmart/data/CommitteeTypes.java
// @XmlRootElement(name="committeeTypes")
// public class CommitteeTypes extends GeneralInfoBase {
// public ArrayList<Type> type;
//
// @XmlType(name="type", namespace="committeeTypes")
// public static class Type {
// public String committeeTypeId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Committees.java
// @XmlRootElement(name="committees")
// public class Committees extends GeneralInfoBase {
// public ArrayList<Committee> committee;
//
// @XmlType(name="committee", namespace="committees")
// public static class Committee {
// public String committeeId;
// public String parentId;
// public String stateId;
// public String committeeTypeId;
// public String name;
// }
// }
// Path: src/main/java/org/votesmart/classes/CommitteeClass.java
import org.votesmart.api.*;
import org.votesmart.data.Committee;
import org.votesmart.data.CommitteeMembers;
import org.votesmart.data.CommitteeTypes;
import org.votesmart.data.Committees;
package org.votesmart.classes;
/**
* <pre>
* Committee Class
*
* * - Required
* * - Multiple rows
*
* Committee.getTypes()
* Returns the committee types(house, senate, joint, etc)
* Input: none
* Output: {@link CommitteeTypes}
*
* Committee.getCommitteesByTypeState()
* Returns the list of committees that fit the criteria
* Input: typeId(Default: All), stateId (Default: NA(fed))
* Output: {@link Committees}
*
* Committee.getCommittee()
* Returns detailed committee data.
* Input: committeeId*
* Output: {@link Committee}
*
* Committee.getCommitteeMembers()
* Returns members of the committee
* Input: committeeId*
* Output: {@link CommitteeMembers}
*
* =========== EXAMPLE USAGE ========
*
* CommitteeClass committeeClass = new CommitteeClass();
*
* Committee committee = committeeClass.getCommittee(committeeByBio.committeeId);
*
* CommitteeTypes committeeTypes = committeeClass.getTypes();
* </pre>
*
*/
public class CommitteeClass extends ClassesBase {
/**
* Constructor for testing purposes.
*
* @param api
*/
public CommitteeClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public CommitteeClass() throws VoteSmartException {
super();
}
/**
* Returns the committee types(house, senate, joint, etc)
*
* @return {@link CommitteeTypes}:
*/
public CommitteeTypes getTypes() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getTypes", null, CommitteeTypes.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState() throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", null, Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId), Committees.class );
}
/**
* Returns the list of committees that fit the criteria.
*
* @param typeId
* @param stateId
* @return {@link Committees}:
*/
public Committees getCommitteesByTypeState(String typeId, String stateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommitteesByTypeState", new ArgMap("typeId", typeId, "stateId", stateId), Committees.class );
}
/**
* Returns detailed committee data.
*
* @param committeeId
* @return {@link Committee}:
*/
public Committee getCommittee(String committeeId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Committee.getCommittee", new ArgMap("committeeId", committeeId), Committee.class );
}
/**
* Returns members of the committee.
*
* @param committeeId
* @return {@link CommitteeMembers}:
*/
| public CommitteeMembers getCommitteeMembers(String committeeId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/RatingClass.java | // Path: src/main/java/org/votesmart/data/Rating.java
// @XmlRootElement(name="rating")
// public class Rating extends GeneralInfoBase {
//
// public ArrayList<CandidateRating> candidateRating;
//
// @XmlType(name="candidateRating", namespace="rating")
// public static class CandidateRating {
// public String candidateId;
// public String rating;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Sig.java
// @XmlRootElement(name="sig")
// public class Sig extends GeneralInfoBase {
// public String sigId;
// public String parentId;
// public String stateId;
// public String name;
// public String description;
// public String address;
// public String city;
// public String state;
// public String zip;
// public String phone1;
// public String phone2;
// public String fax;
// public String email;
// public String url;
// public String contactName;
// }
//
// Path: src/main/java/org/votesmart/data/Sigs.java
// @XmlRootElement(name="sigs")
// public class Sigs extends GeneralInfoBase {
// public ArrayList<Sig> sig;
// @XmlType(name="sig", namespace="sigs")
// public static class Sig {
// public String sigId;
// public String parentId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/SigRating.java
// @XmlRootElement(name="sigRating")
// public class SigRating extends GeneralInfoBase {
// public Sig sig;
// public ArrayList<Rating> rating;
//
// @XmlType(name="sig", namespace="sigRating")
// public static class Sig {
// public String sigId;
// public String name;
// }
// @XmlType(name="rating", namespace="sigRating")
// public static class Rating {
// public String ratingId;
// public String timespan;
// public String ratingName;
// public String ratingText;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Categories.java
// @XmlRootElement(name="categories")
// public class Categories extends GeneralInfoBase {
// public ArrayList<CategoryMin> category;
//
// }
//
// Path: src/main/java/org/votesmart/data/CandidateRating.java
// @XmlRootElement(name="candidateRating")
// public class CandidateRating extends GeneralInfoBase {
// public CandidateTitle candidate;
// public String office;
// public ArrayList<Rating> rating;
//
// @XmlType(name="rating", namespace="candidateRating")
// public static class Rating {
// public String sigId;
// public String ratingId;
// public ArrayList<Category> categories;
// public String timeSpan;
// public String rating;
// public String ratingName;
// public String ratingText;
//
// @XmlType(name="category", namespace="candidateRating.rating")
// public static class Category {
// public String categoryId;
// public String name;
// }
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.Rating;
import org.votesmart.data.Sig;
import org.votesmart.data.Sigs;
import org.votesmart.data.SigRating;
import org.votesmart.data.Categories;
import org.votesmart.data.CandidateRating;
| package org.votesmart.classes;
/**
* <pre>
* Rating Class
*
* * - Required
* * - Multiple rows
*
* Rating.getCategories
* This method dumps categories that contain released ratingss according to state.
* Input: stateId (default: 'NA')
* Output: {@link Categories}
*
* Rating.getSigList
* This method dumps Special Interest Groups according to category and state.
* Input: categoryId*, stateId (default: 'NA')
* Output: {@link Sigs}
*
* Rating.getSig
* This method dumps detailed information an a Special Interest Group.
* Input: sigId*
* Output: {@link Sig}
*
* Rating.getSigRatings
* This method dumps all ratings(scorecards) by a Special Interest Group.
* Input: sigId*
* Output: {@link SigRating}
*
* Rating.getCandidateRating
* This method dumps a candidate's rating by an SIG.
* Input: candidateId*, sigId
* Output: {@link CandidateRating}
*
* Rating.getRating
* This method dumps all candidate ratings from a scorecard by an SIG.
* Input: ratingId*
* Output: {@link Rating}
*
* =========== EXAMPLE USAGE ==================
*
* RatingClass ratingClass = new RatingClass();
*
* // all categories
* Categories categories = ratingClass.getCategories();
*
* // state categories
* categories = ratingClass.getCategories(state.stateId);
* CategoryMin category = categories.category.get(0)
*
* // state sigs (Special Interest Groups)
* Sigs sigs = ratingClass.getSigList(category.categoryId, state.stateId);
* Sigs.Sig sigsSig = sigs.sig.get(0);
*
* // Sig
* Sig sig = ratingClass.getSig(sigs.sig.get(0).sigId);
* </pre>
*
*/
public class RatingClass extends ClassesBase {
/**
* Constructor for testing purposes
*
* @param api
*/
public RatingClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public RatingClass() throws VoteSmartException {
super();
}
/**
* This method dumps categories that contain released ratings according to state.
* Input: stateId (default: 'NA')
*
* @return {@link Categories}
*/
| // Path: src/main/java/org/votesmart/data/Rating.java
// @XmlRootElement(name="rating")
// public class Rating extends GeneralInfoBase {
//
// public ArrayList<CandidateRating> candidateRating;
//
// @XmlType(name="candidateRating", namespace="rating")
// public static class CandidateRating {
// public String candidateId;
// public String rating;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Sig.java
// @XmlRootElement(name="sig")
// public class Sig extends GeneralInfoBase {
// public String sigId;
// public String parentId;
// public String stateId;
// public String name;
// public String description;
// public String address;
// public String city;
// public String state;
// public String zip;
// public String phone1;
// public String phone2;
// public String fax;
// public String email;
// public String url;
// public String contactName;
// }
//
// Path: src/main/java/org/votesmart/data/Sigs.java
// @XmlRootElement(name="sigs")
// public class Sigs extends GeneralInfoBase {
// public ArrayList<Sig> sig;
// @XmlType(name="sig", namespace="sigs")
// public static class Sig {
// public String sigId;
// public String parentId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/SigRating.java
// @XmlRootElement(name="sigRating")
// public class SigRating extends GeneralInfoBase {
// public Sig sig;
// public ArrayList<Rating> rating;
//
// @XmlType(name="sig", namespace="sigRating")
// public static class Sig {
// public String sigId;
// public String name;
// }
// @XmlType(name="rating", namespace="sigRating")
// public static class Rating {
// public String ratingId;
// public String timespan;
// public String ratingName;
// public String ratingText;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Categories.java
// @XmlRootElement(name="categories")
// public class Categories extends GeneralInfoBase {
// public ArrayList<CategoryMin> category;
//
// }
//
// Path: src/main/java/org/votesmart/data/CandidateRating.java
// @XmlRootElement(name="candidateRating")
// public class CandidateRating extends GeneralInfoBase {
// public CandidateTitle candidate;
// public String office;
// public ArrayList<Rating> rating;
//
// @XmlType(name="rating", namespace="candidateRating")
// public static class Rating {
// public String sigId;
// public String ratingId;
// public ArrayList<Category> categories;
// public String timeSpan;
// public String rating;
// public String ratingName;
// public String ratingText;
//
// @XmlType(name="category", namespace="candidateRating.rating")
// public static class Category {
// public String categoryId;
// public String name;
// }
// }
// }
// Path: src/main/java/org/votesmart/classes/RatingClass.java
import org.votesmart.api.*;
import org.votesmart.data.Rating;
import org.votesmart.data.Sig;
import org.votesmart.data.Sigs;
import org.votesmart.data.SigRating;
import org.votesmart.data.Categories;
import org.votesmart.data.CandidateRating;
package org.votesmart.classes;
/**
* <pre>
* Rating Class
*
* * - Required
* * - Multiple rows
*
* Rating.getCategories
* This method dumps categories that contain released ratingss according to state.
* Input: stateId (default: 'NA')
* Output: {@link Categories}
*
* Rating.getSigList
* This method dumps Special Interest Groups according to category and state.
* Input: categoryId*, stateId (default: 'NA')
* Output: {@link Sigs}
*
* Rating.getSig
* This method dumps detailed information an a Special Interest Group.
* Input: sigId*
* Output: {@link Sig}
*
* Rating.getSigRatings
* This method dumps all ratings(scorecards) by a Special Interest Group.
* Input: sigId*
* Output: {@link SigRating}
*
* Rating.getCandidateRating
* This method dumps a candidate's rating by an SIG.
* Input: candidateId*, sigId
* Output: {@link CandidateRating}
*
* Rating.getRating
* This method dumps all candidate ratings from a scorecard by an SIG.
* Input: ratingId*
* Output: {@link Rating}
*
* =========== EXAMPLE USAGE ==================
*
* RatingClass ratingClass = new RatingClass();
*
* // all categories
* Categories categories = ratingClass.getCategories();
*
* // state categories
* categories = ratingClass.getCategories(state.stateId);
* CategoryMin category = categories.category.get(0)
*
* // state sigs (Special Interest Groups)
* Sigs sigs = ratingClass.getSigList(category.categoryId, state.stateId);
* Sigs.Sig sigsSig = sigs.sig.get(0);
*
* // Sig
* Sig sig = ratingClass.getSig(sigs.sig.get(0).sigId);
* </pre>
*
*/
public class RatingClass extends ClassesBase {
/**
* Constructor for testing purposes
*
* @param api
*/
public RatingClass(VoteSmartAPI api) {
super(api);
}
/**
* Default Constructor
*/
public RatingClass() throws VoteSmartException {
super();
}
/**
* This method dumps categories that contain released ratings according to state.
* Input: stateId (default: 'NA')
*
* @return {@link Categories}
*/
| public Categories getCategories() throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/main/java/org/votesmart/classes/RatingClass.java | // Path: src/main/java/org/votesmart/data/Rating.java
// @XmlRootElement(name="rating")
// public class Rating extends GeneralInfoBase {
//
// public ArrayList<CandidateRating> candidateRating;
//
// @XmlType(name="candidateRating", namespace="rating")
// public static class CandidateRating {
// public String candidateId;
// public String rating;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Sig.java
// @XmlRootElement(name="sig")
// public class Sig extends GeneralInfoBase {
// public String sigId;
// public String parentId;
// public String stateId;
// public String name;
// public String description;
// public String address;
// public String city;
// public String state;
// public String zip;
// public String phone1;
// public String phone2;
// public String fax;
// public String email;
// public String url;
// public String contactName;
// }
//
// Path: src/main/java/org/votesmart/data/Sigs.java
// @XmlRootElement(name="sigs")
// public class Sigs extends GeneralInfoBase {
// public ArrayList<Sig> sig;
// @XmlType(name="sig", namespace="sigs")
// public static class Sig {
// public String sigId;
// public String parentId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/SigRating.java
// @XmlRootElement(name="sigRating")
// public class SigRating extends GeneralInfoBase {
// public Sig sig;
// public ArrayList<Rating> rating;
//
// @XmlType(name="sig", namespace="sigRating")
// public static class Sig {
// public String sigId;
// public String name;
// }
// @XmlType(name="rating", namespace="sigRating")
// public static class Rating {
// public String ratingId;
// public String timespan;
// public String ratingName;
// public String ratingText;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Categories.java
// @XmlRootElement(name="categories")
// public class Categories extends GeneralInfoBase {
// public ArrayList<CategoryMin> category;
//
// }
//
// Path: src/main/java/org/votesmart/data/CandidateRating.java
// @XmlRootElement(name="candidateRating")
// public class CandidateRating extends GeneralInfoBase {
// public CandidateTitle candidate;
// public String office;
// public ArrayList<Rating> rating;
//
// @XmlType(name="rating", namespace="candidateRating")
// public static class Rating {
// public String sigId;
// public String ratingId;
// public ArrayList<Category> categories;
// public String timeSpan;
// public String rating;
// public String ratingName;
// public String ratingText;
//
// @XmlType(name="category", namespace="candidateRating.rating")
// public static class Category {
// public String categoryId;
// public String name;
// }
// }
// }
| import org.votesmart.api.*;
import org.votesmart.data.Rating;
import org.votesmart.data.Sig;
import org.votesmart.data.Sigs;
import org.votesmart.data.SigRating;
import org.votesmart.data.Categories;
import org.votesmart.data.CandidateRating;
| }
/**
* This method dumps a candidate's rating by an SIG.
*
* @param candidateId
* @return {@link CandidateRating}
*/
public CandidateRating getCandidateRating(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Rating.getCandidateRating", new ArgMap("candidateId", candidateId), CandidateRating.class );
}
/**
* This method dumps a candidate's rating by an SIG.
*
* @param candidateId
* @param sigId
* @return {@link CandidateRating}
*/
public CandidateRating getCandidateRating(String candidateId, String sigId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Rating.getCandidateRating", new ArgMap("candidateId", candidateId, "sigId", sigId), CandidateRating.class );
}
/**
* This method dumps all candidate ratings from a scorecard by an SIG.
*
* @param ratingId
* @return {@link Rating}
* @throws VoteSmartException, VoteSmartErrorException
*/
| // Path: src/main/java/org/votesmart/data/Rating.java
// @XmlRootElement(name="rating")
// public class Rating extends GeneralInfoBase {
//
// public ArrayList<CandidateRating> candidateRating;
//
// @XmlType(name="candidateRating", namespace="rating")
// public static class CandidateRating {
// public String candidateId;
// public String rating;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Sig.java
// @XmlRootElement(name="sig")
// public class Sig extends GeneralInfoBase {
// public String sigId;
// public String parentId;
// public String stateId;
// public String name;
// public String description;
// public String address;
// public String city;
// public String state;
// public String zip;
// public String phone1;
// public String phone2;
// public String fax;
// public String email;
// public String url;
// public String contactName;
// }
//
// Path: src/main/java/org/votesmart/data/Sigs.java
// @XmlRootElement(name="sigs")
// public class Sigs extends GeneralInfoBase {
// public ArrayList<Sig> sig;
// @XmlType(name="sig", namespace="sigs")
// public static class Sig {
// public String sigId;
// public String parentId;
// public String name;
// }
// }
//
// Path: src/main/java/org/votesmart/data/SigRating.java
// @XmlRootElement(name="sigRating")
// public class SigRating extends GeneralInfoBase {
// public Sig sig;
// public ArrayList<Rating> rating;
//
// @XmlType(name="sig", namespace="sigRating")
// public static class Sig {
// public String sigId;
// public String name;
// }
// @XmlType(name="rating", namespace="sigRating")
// public static class Rating {
// public String ratingId;
// public String timespan;
// public String ratingName;
// public String ratingText;
// }
// }
//
// Path: src/main/java/org/votesmart/data/Categories.java
// @XmlRootElement(name="categories")
// public class Categories extends GeneralInfoBase {
// public ArrayList<CategoryMin> category;
//
// }
//
// Path: src/main/java/org/votesmart/data/CandidateRating.java
// @XmlRootElement(name="candidateRating")
// public class CandidateRating extends GeneralInfoBase {
// public CandidateTitle candidate;
// public String office;
// public ArrayList<Rating> rating;
//
// @XmlType(name="rating", namespace="candidateRating")
// public static class Rating {
// public String sigId;
// public String ratingId;
// public ArrayList<Category> categories;
// public String timeSpan;
// public String rating;
// public String ratingName;
// public String ratingText;
//
// @XmlType(name="category", namespace="candidateRating.rating")
// public static class Category {
// public String categoryId;
// public String name;
// }
// }
// }
// Path: src/main/java/org/votesmart/classes/RatingClass.java
import org.votesmart.api.*;
import org.votesmart.data.Rating;
import org.votesmart.data.Sig;
import org.votesmart.data.Sigs;
import org.votesmart.data.SigRating;
import org.votesmart.data.Categories;
import org.votesmart.data.CandidateRating;
}
/**
* This method dumps a candidate's rating by an SIG.
*
* @param candidateId
* @return {@link CandidateRating}
*/
public CandidateRating getCandidateRating(String candidateId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Rating.getCandidateRating", new ArgMap("candidateId", candidateId), CandidateRating.class );
}
/**
* This method dumps a candidate's rating by an SIG.
*
* @param candidateId
* @param sigId
* @return {@link CandidateRating}
*/
public CandidateRating getCandidateRating(String candidateId, String sigId) throws VoteSmartException, VoteSmartErrorException {
return api.query("Rating.getCandidateRating", new ArgMap("candidateId", candidateId, "sigId", sigId), CandidateRating.class );
}
/**
* This method dumps all candidate ratings from a scorecard by an SIG.
*
* @param ratingId
* @return {@link Rating}
* @throws VoteSmartException, VoteSmartErrorException
*/
| public Rating getRating(String ratingId) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/test/java/org/votesmart/testapi/TestVoteSmart.java | // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
| package org.votesmart.testapi;
/**
* TestVoteSmart.
*
* This class will load from a zip file in the (test) resources directory
* and unmarshall the XML documents inside. It is used with
* {@link TestVoteSmartBase}
*
*/
public class TestVoteSmart {
private Unmarshaller unmarshaller;
private char[] buffer;
private TreeMap<String, ZipEntry> mapEntries;
private ZipFile zipFile;
public TestVoteSmart(ResourceBundle bundle) {
mapEntries = new TreeMap<String, ZipEntry>();
try {
zipFile = new ZipFile( TestVoteSmart.class.getResource("/AllThingsCalifornia.zip").getFile() );
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while ( entries.hasMoreElements() ) {
ZipEntry entry = entries.nextElement();
mapEntries.put(entry.getName(), entry);
}
unmarshaller = JAXBContext.newInstance( "org.votesmart.data" ).createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException(e);
}
// arbitrary large value
buffer = new char[ 262144 ];
}
/**
* Queries the API server for the information requested
*
* @param method
* The method to be called on the API Server
* @param args
* An IdentityHashMap<String, String> of the arguments for the
* method
* @return The XML document as a XOM Document.
*
* @throws VoteSmartException
* @throws VoteSmartErrorException
*/
| // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
// Path: src/test/java/org/votesmart/testapi/TestVoteSmart.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
package org.votesmart.testapi;
/**
* TestVoteSmart.
*
* This class will load from a zip file in the (test) resources directory
* and unmarshall the XML documents inside. It is used with
* {@link TestVoteSmartBase}
*
*/
public class TestVoteSmart {
private Unmarshaller unmarshaller;
private char[] buffer;
private TreeMap<String, ZipEntry> mapEntries;
private ZipFile zipFile;
public TestVoteSmart(ResourceBundle bundle) {
mapEntries = new TreeMap<String, ZipEntry>();
try {
zipFile = new ZipFile( TestVoteSmart.class.getResource("/AllThingsCalifornia.zip").getFile() );
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while ( entries.hasMoreElements() ) {
ZipEntry entry = entries.nextElement();
mapEntries.put(entry.getName(), entry);
}
unmarshaller = JAXBContext.newInstance( "org.votesmart.data" ).createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException(e);
}
// arbitrary large value
buffer = new char[ 262144 ];
}
/**
* Queries the API server for the information requested
*
* @param method
* The method to be called on the API Server
* @param args
* An IdentityHashMap<String, String> of the arguments for the
* method
* @return The XML document as a XOM Document.
*
* @throws VoteSmartException
* @throws VoteSmartErrorException
*/
| public <T> T query(String method, ArgMap argMap, Class<T> responseType) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/test/java/org/votesmart/testapi/TestVoteSmart.java | // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
| package org.votesmart.testapi;
/**
* TestVoteSmart.
*
* This class will load from a zip file in the (test) resources directory
* and unmarshall the XML documents inside. It is used with
* {@link TestVoteSmartBase}
*
*/
public class TestVoteSmart {
private Unmarshaller unmarshaller;
private char[] buffer;
private TreeMap<String, ZipEntry> mapEntries;
private ZipFile zipFile;
public TestVoteSmart(ResourceBundle bundle) {
mapEntries = new TreeMap<String, ZipEntry>();
try {
zipFile = new ZipFile( TestVoteSmart.class.getResource("/AllThingsCalifornia.zip").getFile() );
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while ( entries.hasMoreElements() ) {
ZipEntry entry = entries.nextElement();
mapEntries.put(entry.getName(), entry);
}
unmarshaller = JAXBContext.newInstance( "org.votesmart.data" ).createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException(e);
}
// arbitrary large value
buffer = new char[ 262144 ];
}
/**
* Queries the API server for the information requested
*
* @param method
* The method to be called on the API Server
* @param args
* An IdentityHashMap<String, String> of the arguments for the
* method
* @return The XML document as a XOM Document.
*
* @throws VoteSmartException
* @throws VoteSmartErrorException
*/
| // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
// Path: src/test/java/org/votesmart/testapi/TestVoteSmart.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
package org.votesmart.testapi;
/**
* TestVoteSmart.
*
* This class will load from a zip file in the (test) resources directory
* and unmarshall the XML documents inside. It is used with
* {@link TestVoteSmartBase}
*
*/
public class TestVoteSmart {
private Unmarshaller unmarshaller;
private char[] buffer;
private TreeMap<String, ZipEntry> mapEntries;
private ZipFile zipFile;
public TestVoteSmart(ResourceBundle bundle) {
mapEntries = new TreeMap<String, ZipEntry>();
try {
zipFile = new ZipFile( TestVoteSmart.class.getResource("/AllThingsCalifornia.zip").getFile() );
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while ( entries.hasMoreElements() ) {
ZipEntry entry = entries.nextElement();
mapEntries.put(entry.getName(), entry);
}
unmarshaller = JAXBContext.newInstance( "org.votesmart.data" ).createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException(e);
}
// arbitrary large value
buffer = new char[ 262144 ];
}
/**
* Queries the API server for the information requested
*
* @param method
* The method to be called on the API Server
* @param args
* An IdentityHashMap<String, String> of the arguments for the
* method
* @return The XML document as a XOM Document.
*
* @throws VoteSmartException
* @throws VoteSmartErrorException
*/
| public <T> T query(String method, ArgMap argMap, Class<T> responseType) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/test/java/org/votesmart/testapi/TestVoteSmart.java | // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
| package org.votesmart.testapi;
/**
* TestVoteSmart.
*
* This class will load from a zip file in the (test) resources directory
* and unmarshall the XML documents inside. It is used with
* {@link TestVoteSmartBase}
*
*/
public class TestVoteSmart {
private Unmarshaller unmarshaller;
private char[] buffer;
private TreeMap<String, ZipEntry> mapEntries;
private ZipFile zipFile;
public TestVoteSmart(ResourceBundle bundle) {
mapEntries = new TreeMap<String, ZipEntry>();
try {
zipFile = new ZipFile( TestVoteSmart.class.getResource("/AllThingsCalifornia.zip").getFile() );
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while ( entries.hasMoreElements() ) {
ZipEntry entry = entries.nextElement();
mapEntries.put(entry.getName(), entry);
}
unmarshaller = JAXBContext.newInstance( "org.votesmart.data" ).createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException(e);
}
// arbitrary large value
buffer = new char[ 262144 ];
}
/**
* Queries the API server for the information requested
*
* @param method
* The method to be called on the API Server
* @param args
* An IdentityHashMap<String, String> of the arguments for the
* method
* @return The XML document as a XOM Document.
*
* @throws VoteSmartException
* @throws VoteSmartErrorException
*/
| // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
// Path: src/test/java/org/votesmart/testapi/TestVoteSmart.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
package org.votesmart.testapi;
/**
* TestVoteSmart.
*
* This class will load from a zip file in the (test) resources directory
* and unmarshall the XML documents inside. It is used with
* {@link TestVoteSmartBase}
*
*/
public class TestVoteSmart {
private Unmarshaller unmarshaller;
private char[] buffer;
private TreeMap<String, ZipEntry> mapEntries;
private ZipFile zipFile;
public TestVoteSmart(ResourceBundle bundle) {
mapEntries = new TreeMap<String, ZipEntry>();
try {
zipFile = new ZipFile( TestVoteSmart.class.getResource("/AllThingsCalifornia.zip").getFile() );
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while ( entries.hasMoreElements() ) {
ZipEntry entry = entries.nextElement();
mapEntries.put(entry.getName(), entry);
}
unmarshaller = JAXBContext.newInstance( "org.votesmart.data" ).createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException(e);
}
// arbitrary large value
buffer = new char[ 262144 ];
}
/**
* Queries the API server for the information requested
*
* @param method
* The method to be called on the API Server
* @param args
* An IdentityHashMap<String, String> of the arguments for the
* method
* @return The XML document as a XOM Document.
*
* @throws VoteSmartException
* @throws VoteSmartErrorException
*/
| public <T> T query(String method, ArgMap argMap, Class<T> responseType) throws VoteSmartException, VoteSmartErrorException {
|
karlnicholas/votesmart | src/test/java/org/votesmart/testapi/TestVoteSmart.java | // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
| try {
StringBuilder filename = new StringBuilder( method );
if ( argMap!= null ) {
for (String key: argMap.keySet() )
{
String value = argMap.get(key);
filename.append('.');
filename.append( key );
filename.append('.');
filename.append( value );
}
}
filename.append(".xml" );
ZipEntry entry = mapEntries.get(filename.toString());
BufferedReader breader = new BufferedReader(new InputStreamReader( zipFile.getInputStream(entry), Charset.forName("UTF-8") ) );
StringBuilder XMLBuilder = new StringBuilder();
int read;
while ( (read = breader.read(buffer)) != -1 ) {
XMLBuilder.append(buffer, 0, read);
}
breader.close();
String XMLStr = XMLBuilder.toString();
StringReader reader = new StringReader(XMLStr);
JAXBElement<T> e = unmarshaller.unmarshal(new StreamSource(reader), responseType);
if ( e.getName().getLocalPart().equals("error") ) {
| // Path: src/main/java/org/votesmart/api/ArgMap.java
// public class ArgMap extends TreeMap<String, String> {
// private static final long serialVersionUID = -2664255408377082118L;
//
// public ArgMap(String... args ) {
// for ( int i=0; i<args.length; i+=2) {
// this.put(args[i], args[i+1]);
// }
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartErrorException.java
// public class VoteSmartErrorException extends Exception {
// private static final long serialVersionUID = 2196788960724030978L;
// public ErrorBase errorBase;
// public String method;
// public ArgMap argMap;
// public VoteSmartErrorException(ErrorBase errorBase, String method, ArgMap argMap) {
// super(errorBase.errorMessage);
// this.errorBase = errorBase;
// this.method = method;
// this.argMap = argMap;
// }
// }
//
// Path: src/main/java/org/votesmart/api/VoteSmartException.java
// public class VoteSmartException extends Exception {
// private static final long serialVersionUID = 6179623710020364382L;
//
// public VoteSmartException (Exception e ) {
// super(e);
// }
//
// public VoteSmartException (String msg) {
// super(msg);
// }
//
// public VoteSmartException(String msg, Exception e ) {
// super(msg, e);
// }
// }
//
// Path: src/main/java/org/votesmart/data/ErrorBase.java
// @XmlRootElement(name="error")
// public class ErrorBase {
//
// public String errorMessage;
// }
// Path: src/test/java/org/votesmart/testapi/TestVoteSmart.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.votesmart.api.ArgMap;
import org.votesmart.api.VoteSmartErrorException;
import org.votesmart.api.VoteSmartException;
import org.votesmart.data.ErrorBase;
try {
StringBuilder filename = new StringBuilder( method );
if ( argMap!= null ) {
for (String key: argMap.keySet() )
{
String value = argMap.get(key);
filename.append('.');
filename.append( key );
filename.append('.');
filename.append( value );
}
}
filename.append(".xml" );
ZipEntry entry = mapEntries.get(filename.toString());
BufferedReader breader = new BufferedReader(new InputStreamReader( zipFile.getInputStream(entry), Charset.forName("UTF-8") ) );
StringBuilder XMLBuilder = new StringBuilder();
int read;
while ( (read = breader.read(buffer)) != -1 ) {
XMLBuilder.append(buffer, 0, read);
}
breader.close();
String XMLStr = XMLBuilder.toString();
StringReader reader = new StringReader(XMLStr);
JAXBElement<T> e = unmarshaller.unmarshal(new StreamSource(reader), responseType);
if ( e.getName().getLocalPart().equals("error") ) {
| ErrorBase error = unmarshaller.unmarshal( new StreamSource( reader = new StringReader(XMLStr) ), ErrorBase.class ).getValue();
|
graywolf336/CasinoSlots | src/main/java/com/craftyn/casinoslots/classes/SlotMachine.java | // Path: src/main/java/com/craftyn/casinoslots/CasinoSlotsStaticAPI.java
// public class CasinoSlotsStaticAPI {
// public static CasinoSlots plugin;
//
// protected CasinoSlotsStaticAPI(CasinoSlots pl) {
// plugin = pl;
// }
//
// public static ActionFactory getActionFactory() {
// return plugin.getActionFactory();
// }
//
// public static TypeManager getTypeManager() {
// return plugin.getTypeManager();
// }
//
// public static SlotManager getSlotManager() {
// return plugin.getSlotManager();
// }
//
// public static Economy getEconomy() {
// return plugin.getEconomy();
// }
//
// public static void sendMessageToPlayer(CommandSender recipient, String message) {
// plugin.sendMessage(recipient, message);
// }
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.material.MaterialData;
import com.craftyn.casinoslots.CasinoSlotsStaticAPI; | package com.craftyn.casinoslots.classes;
/**
* Represents a slot machine.
*
* @author graywolf336
* @version 3.0.0
* @since 1.0.0
*/
@SerializableAs(value = "CasinoSlotsSlotMachine")
public class SlotMachine implements ConfigurationSerializable {
private String name, typeName;
private SlotMachineOwner owner;
private SimpleLocation controller;
private List<SimpleLocation> blocks;
public SlotMachine(String name) {
this.name = name;
this.blocks = new ArrayList<SimpleLocation>();
}
/**
* Sets the name of the {@link SlotMachine}.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the name of this {@link SlotMachine}.
*
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Sets the {@link SlotType} of this {@link SlotMachine}.
*
* @param type the {@link SlotType} to set.
*/
public void setType(SlotType type) {
this.typeName = type.getName();
}
public SlotType getType() { | // Path: src/main/java/com/craftyn/casinoslots/CasinoSlotsStaticAPI.java
// public class CasinoSlotsStaticAPI {
// public static CasinoSlots plugin;
//
// protected CasinoSlotsStaticAPI(CasinoSlots pl) {
// plugin = pl;
// }
//
// public static ActionFactory getActionFactory() {
// return plugin.getActionFactory();
// }
//
// public static TypeManager getTypeManager() {
// return plugin.getTypeManager();
// }
//
// public static SlotManager getSlotManager() {
// return plugin.getSlotManager();
// }
//
// public static Economy getEconomy() {
// return plugin.getEconomy();
// }
//
// public static void sendMessageToPlayer(CommandSender recipient, String message) {
// plugin.sendMessage(recipient, message);
// }
// }
// Path: src/main/java/com/craftyn/casinoslots/classes/SlotMachine.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.material.MaterialData;
import com.craftyn.casinoslots.CasinoSlotsStaticAPI;
package com.craftyn.casinoslots.classes;
/**
* Represents a slot machine.
*
* @author graywolf336
* @version 3.0.0
* @since 1.0.0
*/
@SerializableAs(value = "CasinoSlotsSlotMachine")
public class SlotMachine implements ConfigurationSerializable {
private String name, typeName;
private SlotMachineOwner owner;
private SimpleLocation controller;
private List<SimpleLocation> blocks;
public SlotMachine(String name) {
this.name = name;
this.blocks = new ArrayList<SimpleLocation>();
}
/**
* Sets the name of the {@link SlotMachine}.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the name of this {@link SlotMachine}.
*
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Sets the {@link SlotType} of this {@link SlotMachine}.
*
* @param type the {@link SlotType} to set.
*/
public void setType(SlotType type) {
this.typeName = type.getName();
}
public SlotType getType() { | return CasinoSlotsStaticAPI.getTypeManager().getType(this.typeName); |
graywolf336/CasinoSlots | src/main/java/com/craftyn/casinoslots/slot/game/RotateTask.java | // Path: src/main/java/com/craftyn/casinoslots/classes/ReelBlock.java
// public class ReelBlock {
// private MaterialData data;
//
// /**
// * Creates a new {@link ReelBlock}.
// *
// * @param data the {@link MaterialData} for the reel's block
// */
// public ReelBlock(MaterialData data) {
// this.data = data;
// }
//
// /**
// * The {@link MaterialData} for the reel block.
// *
// * @return the {@link MaterialData} we are using
// */
// public MaterialData getBlockData() {
// return this.data;
// }
//
// /**
// * The string value of this, but with the typed name instead of number.
// *
// * @return string of the MaterialData like "stone:2".
// */
// @SuppressWarnings("deprecation")
// public String toString() {
// return this.data.getItemType().toString().toLowerCase() + ":" + this.data.getData();
// }
//
// public boolean equals(Object object) {
// if (object == null)
// return false;
// else if (!(object instanceof ReelBlock))
// return false;
//
// ReelBlock b = (ReelBlock) object;
//
// return this.data.equals(b.getBlockData());
// }
//
// @SuppressWarnings("deprecation")
// public static ReelBlock fromBlock(Block block) {
// return new ReelBlock(new MaterialData(block.getType(), block.getData()));
// }
// }
//
// Path: src/main/java/com/craftyn/casinoslots/enums/SlotMachineColumnType.java
// public enum SlotMachineColumnType {
// /** The first column in a slot machine, the one which runs the longest. */
// FIRST(0, 100L),
// /** The second column in a slot machine, the one which runs the second longest. */
// SECOND(1, 80L),
// /** The third column in a slot machine, the one which runs the shortest amount of time. */
// THIRD(2, 60L);
//
// private int number;
// private long delay;
//
// private SlotMachineColumnType(int number, long delay) {
// this.number = number;
// this.delay = delay;
// }
//
// /**
// * The index of the column.
// *
// * @return the index number of the column
// */
// public int getIndex() {
// return this.number;
// }
//
// /**
// * The index the first row in this column's block is at, bottom most.
// *
// * @return the index of the first row's block
// */
// public int getFirstRow() {
// return this.number + 6;
// }
//
// /**
// * The index the second row in this column's block is at, middle.
// *
// * @return the index of the second row's block
// */
// public int getSecondRow() {
// return this.number + 3;
// }
//
// /**
// * The index the third row in this column's block is at, top most.
// *
// * @return the index of the third row's block
// */
// public int getThirdRow() {
// return this.number;
// }
//
// /**
// * The delay for the rotation tasks.
// *
// * @return the delay to be applied to the rotate tasks
// */
// public long getDelay() {
// return this.delay;
// }
// }
| import java.util.ArrayList;
import java.util.Random;
import org.bukkit.block.Block;
import org.bukkit.material.MaterialData;
import com.craftyn.casinoslots.classes.ReelBlock;
import com.craftyn.casinoslots.enums.SlotMachineColumnType;
| package com.craftyn.casinoslots.slot.game;
public class RotateTask implements Runnable {
private Game game;
| // Path: src/main/java/com/craftyn/casinoslots/classes/ReelBlock.java
// public class ReelBlock {
// private MaterialData data;
//
// /**
// * Creates a new {@link ReelBlock}.
// *
// * @param data the {@link MaterialData} for the reel's block
// */
// public ReelBlock(MaterialData data) {
// this.data = data;
// }
//
// /**
// * The {@link MaterialData} for the reel block.
// *
// * @return the {@link MaterialData} we are using
// */
// public MaterialData getBlockData() {
// return this.data;
// }
//
// /**
// * The string value of this, but with the typed name instead of number.
// *
// * @return string of the MaterialData like "stone:2".
// */
// @SuppressWarnings("deprecation")
// public String toString() {
// return this.data.getItemType().toString().toLowerCase() + ":" + this.data.getData();
// }
//
// public boolean equals(Object object) {
// if (object == null)
// return false;
// else if (!(object instanceof ReelBlock))
// return false;
//
// ReelBlock b = (ReelBlock) object;
//
// return this.data.equals(b.getBlockData());
// }
//
// @SuppressWarnings("deprecation")
// public static ReelBlock fromBlock(Block block) {
// return new ReelBlock(new MaterialData(block.getType(), block.getData()));
// }
// }
//
// Path: src/main/java/com/craftyn/casinoslots/enums/SlotMachineColumnType.java
// public enum SlotMachineColumnType {
// /** The first column in a slot machine, the one which runs the longest. */
// FIRST(0, 100L),
// /** The second column in a slot machine, the one which runs the second longest. */
// SECOND(1, 80L),
// /** The third column in a slot machine, the one which runs the shortest amount of time. */
// THIRD(2, 60L);
//
// private int number;
// private long delay;
//
// private SlotMachineColumnType(int number, long delay) {
// this.number = number;
// this.delay = delay;
// }
//
// /**
// * The index of the column.
// *
// * @return the index number of the column
// */
// public int getIndex() {
// return this.number;
// }
//
// /**
// * The index the first row in this column's block is at, bottom most.
// *
// * @return the index of the first row's block
// */
// public int getFirstRow() {
// return this.number + 6;
// }
//
// /**
// * The index the second row in this column's block is at, middle.
// *
// * @return the index of the second row's block
// */
// public int getSecondRow() {
// return this.number + 3;
// }
//
// /**
// * The index the third row in this column's block is at, top most.
// *
// * @return the index of the third row's block
// */
// public int getThirdRow() {
// return this.number;
// }
//
// /**
// * The delay for the rotation tasks.
// *
// * @return the delay to be applied to the rotate tasks
// */
// public long getDelay() {
// return this.delay;
// }
// }
// Path: src/main/java/com/craftyn/casinoslots/slot/game/RotateTask.java
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.block.Block;
import org.bukkit.material.MaterialData;
import com.craftyn.casinoslots.classes.ReelBlock;
import com.craftyn.casinoslots.enums.SlotMachineColumnType;
package com.craftyn.casinoslots.slot.game;
public class RotateTask implements Runnable {
private Game game;
| private SlotMachineColumnType column;
|
graywolf336/CasinoSlots | src/main/java/com/craftyn/casinoslots/slot/game/RotateTask.java | // Path: src/main/java/com/craftyn/casinoslots/classes/ReelBlock.java
// public class ReelBlock {
// private MaterialData data;
//
// /**
// * Creates a new {@link ReelBlock}.
// *
// * @param data the {@link MaterialData} for the reel's block
// */
// public ReelBlock(MaterialData data) {
// this.data = data;
// }
//
// /**
// * The {@link MaterialData} for the reel block.
// *
// * @return the {@link MaterialData} we are using
// */
// public MaterialData getBlockData() {
// return this.data;
// }
//
// /**
// * The string value of this, but with the typed name instead of number.
// *
// * @return string of the MaterialData like "stone:2".
// */
// @SuppressWarnings("deprecation")
// public String toString() {
// return this.data.getItemType().toString().toLowerCase() + ":" + this.data.getData();
// }
//
// public boolean equals(Object object) {
// if (object == null)
// return false;
// else if (!(object instanceof ReelBlock))
// return false;
//
// ReelBlock b = (ReelBlock) object;
//
// return this.data.equals(b.getBlockData());
// }
//
// @SuppressWarnings("deprecation")
// public static ReelBlock fromBlock(Block block) {
// return new ReelBlock(new MaterialData(block.getType(), block.getData()));
// }
// }
//
// Path: src/main/java/com/craftyn/casinoslots/enums/SlotMachineColumnType.java
// public enum SlotMachineColumnType {
// /** The first column in a slot machine, the one which runs the longest. */
// FIRST(0, 100L),
// /** The second column in a slot machine, the one which runs the second longest. */
// SECOND(1, 80L),
// /** The third column in a slot machine, the one which runs the shortest amount of time. */
// THIRD(2, 60L);
//
// private int number;
// private long delay;
//
// private SlotMachineColumnType(int number, long delay) {
// this.number = number;
// this.delay = delay;
// }
//
// /**
// * The index of the column.
// *
// * @return the index number of the column
// */
// public int getIndex() {
// return this.number;
// }
//
// /**
// * The index the first row in this column's block is at, bottom most.
// *
// * @return the index of the first row's block
// */
// public int getFirstRow() {
// return this.number + 6;
// }
//
// /**
// * The index the second row in this column's block is at, middle.
// *
// * @return the index of the second row's block
// */
// public int getSecondRow() {
// return this.number + 3;
// }
//
// /**
// * The index the third row in this column's block is at, top most.
// *
// * @return the index of the third row's block
// */
// public int getThirdRow() {
// return this.number;
// }
//
// /**
// * The delay for the rotation tasks.
// *
// * @return the delay to be applied to the rotate tasks
// */
// public long getDelay() {
// return this.delay;
// }
// }
| import java.util.ArrayList;
import java.util.Random;
import org.bukkit.block.Block;
import org.bukkit.material.MaterialData;
import com.craftyn.casinoslots.classes.ReelBlock;
import com.craftyn.casinoslots.enums.SlotMachineColumnType;
| package com.craftyn.casinoslots.slot.game;
public class RotateTask implements Runnable {
private Game game;
private SlotMachineColumnType column;
private Random generator;
| // Path: src/main/java/com/craftyn/casinoslots/classes/ReelBlock.java
// public class ReelBlock {
// private MaterialData data;
//
// /**
// * Creates a new {@link ReelBlock}.
// *
// * @param data the {@link MaterialData} for the reel's block
// */
// public ReelBlock(MaterialData data) {
// this.data = data;
// }
//
// /**
// * The {@link MaterialData} for the reel block.
// *
// * @return the {@link MaterialData} we are using
// */
// public MaterialData getBlockData() {
// return this.data;
// }
//
// /**
// * The string value of this, but with the typed name instead of number.
// *
// * @return string of the MaterialData like "stone:2".
// */
// @SuppressWarnings("deprecation")
// public String toString() {
// return this.data.getItemType().toString().toLowerCase() + ":" + this.data.getData();
// }
//
// public boolean equals(Object object) {
// if (object == null)
// return false;
// else if (!(object instanceof ReelBlock))
// return false;
//
// ReelBlock b = (ReelBlock) object;
//
// return this.data.equals(b.getBlockData());
// }
//
// @SuppressWarnings("deprecation")
// public static ReelBlock fromBlock(Block block) {
// return new ReelBlock(new MaterialData(block.getType(), block.getData()));
// }
// }
//
// Path: src/main/java/com/craftyn/casinoslots/enums/SlotMachineColumnType.java
// public enum SlotMachineColumnType {
// /** The first column in a slot machine, the one which runs the longest. */
// FIRST(0, 100L),
// /** The second column in a slot machine, the one which runs the second longest. */
// SECOND(1, 80L),
// /** The third column in a slot machine, the one which runs the shortest amount of time. */
// THIRD(2, 60L);
//
// private int number;
// private long delay;
//
// private SlotMachineColumnType(int number, long delay) {
// this.number = number;
// this.delay = delay;
// }
//
// /**
// * The index of the column.
// *
// * @return the index number of the column
// */
// public int getIndex() {
// return this.number;
// }
//
// /**
// * The index the first row in this column's block is at, bottom most.
// *
// * @return the index of the first row's block
// */
// public int getFirstRow() {
// return this.number + 6;
// }
//
// /**
// * The index the second row in this column's block is at, middle.
// *
// * @return the index of the second row's block
// */
// public int getSecondRow() {
// return this.number + 3;
// }
//
// /**
// * The index the third row in this column's block is at, top most.
// *
// * @return the index of the third row's block
// */
// public int getThirdRow() {
// return this.number;
// }
//
// /**
// * The delay for the rotation tasks.
// *
// * @return the delay to be applied to the rotate tasks
// */
// public long getDelay() {
// return this.delay;
// }
// }
// Path: src/main/java/com/craftyn/casinoslots/slot/game/RotateTask.java
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.block.Block;
import org.bukkit.material.MaterialData;
import com.craftyn.casinoslots.classes.ReelBlock;
import com.craftyn.casinoslots.enums.SlotMachineColumnType;
package com.craftyn.casinoslots.slot.game;
public class RotateTask implements Runnable {
private Game game;
private SlotMachineColumnType column;
private Random generator;
| private ArrayList<ReelBlock> reelBlocks;
|
graywolf336/CasinoSlots | src/main/java/com/craftyn/casinoslots/classes/Reward.java | // Path: src/main/java/com/craftyn/casinoslots/actions/Action.java
// public abstract class Action implements IAction {
// public Action(CasinoSlots plugin, String... args) throws ActionLoadingException {
// plugin.debug("Loading the action: " + this.getClass().getSimpleName());
// }
// }
| import java.util.ArrayList;
import java.util.List;
import com.craftyn.casinoslots.actions.Action; | package com.craftyn.casinoslots.classes;
/**
* Representation of a reward to be given out when a slot machine is won.
*
* @author graywolf336
* @since 1.0.0
* @version 2.5.0
*/
public class Reward {
private String message = "";
private double money = 0; | // Path: src/main/java/com/craftyn/casinoslots/actions/Action.java
// public abstract class Action implements IAction {
// public Action(CasinoSlots plugin, String... args) throws ActionLoadingException {
// plugin.debug("Loading the action: " + this.getClass().getSimpleName());
// }
// }
// Path: src/main/java/com/craftyn/casinoslots/classes/Reward.java
import java.util.ArrayList;
import java.util.List;
import com.craftyn.casinoslots.actions.Action;
package com.craftyn.casinoslots.classes;
/**
* Representation of a reward to be given out when a slot machine is won.
*
* @author graywolf336
* @since 1.0.0
* @version 2.5.0
*/
public class Reward {
private String message = "";
private double money = 0; | private List<Action> actions = new ArrayList<Action>(); |
digitalfondue/npjt-extra | src/main/java/ch/digitalfondue/npjt/ConstructorAnnotationRowMapper.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
| import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.Assert;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
public class ConstructorAnnotationRowMapper<T> implements RowMapper<T> {
private final Constructor<T> con; | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
// Path: src/main/java/ch/digitalfondue/npjt/ConstructorAnnotationRowMapper.java
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.Assert;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
public class ConstructorAnnotationRowMapper<T> implements RowMapper<T> {
private final Constructor<T> con; | private final ColumnMapper[] mappedColumn; |
digitalfondue/npjt-extra | src/main/java/ch/digitalfondue/npjt/ConstructorAnnotationRowMapper.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
| import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.Assert;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory; | Constructor<?> con = clazz.getConstructors()[0];
if (con.getParameterTypes().length == 0) {
return false;
}
Annotation[][] parameterAnnotations = con.getParameterAnnotations();
for (Annotation[] as : parameterAnnotations) {
if (!hasColumnAnnotation(as)) {
return false;
}
}
return true;
}
private static boolean hasColumnAnnotation(Annotation[] as) {
if (as == null || as.length == 0) {
return false;
}
for (Annotation a : as) {
if (a.annotationType().isAssignableFrom(Column.class)) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked") | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
// Path: src/main/java/ch/digitalfondue/npjt/ConstructorAnnotationRowMapper.java
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.Assert;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
Constructor<?> con = clazz.getConstructors()[0];
if (con.getParameterTypes().length == 0) {
return false;
}
Annotation[][] parameterAnnotations = con.getParameterAnnotations();
for (Annotation[] as : parameterAnnotations) {
if (!hasColumnAnnotation(as)) {
return false;
}
}
return true;
}
private static boolean hasColumnAnnotation(Annotation[] as) {
if (as == null || as.length == 0) {
return false;
}
for (Annotation a : as) {
if (a.annotationType().isAssignableFrom(Column.class)) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked") | public ConstructorAnnotationRowMapper(Class<T> clazz, Collection<ColumnMapperFactory> columnMapperFactories) { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/query/CustomJSONQueriesTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.query;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class,
CustomJSONQueriesTest.ColumnMapperAndParametersConfiguration.class,
QueryScannerConfiguration.class})
public class CustomJSONQueriesTest {
@Autowired
JsonQueries jq;
private static Gson JSON = new GsonBuilder().create();
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
| // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/query/CustomJSONQueriesTest.java
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.query;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class,
CustomJSONQueriesTest.ColumnMapperAndParametersConfiguration.class,
QueryScannerConfiguration.class})
public class CustomJSONQueriesTest {
@Autowired
JsonQueries jq;
private static Gson JSON = new GsonBuilder().create();
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
| private static class JsonColumnMapper extends ColumnMapper { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/query/CustomJSONQueriesTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map; |
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
private static class JsonColumnMapper extends ColumnMapper {
JsonColumnMapper(String name, Class<?> paramType) {
super(name, paramType);
}
@Override
public Object getObject(ResultSet rs) throws SQLException {
return JSON.fromJson(rs.getString(name), paramType);
}
}
private static boolean containAsJsonAnnotation(Annotation[] annotations) {
if(annotations == null) {
return false;
}
for(Annotation annotation : annotations) {
if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
| // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/query/CustomJSONQueriesTest.java
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
private static class JsonColumnMapper extends ColumnMapper {
JsonColumnMapper(String name, Class<?> paramType) {
super(name, paramType);
}
@Override
public Object getObject(ResultSet rs) throws SQLException {
return JSON.fromJson(rs.getString(name), paramType);
}
}
private static boolean containAsJsonAnnotation(Annotation[] annotations) {
if(annotations == null) {
return false;
}
for(Annotation annotation : annotations) {
if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
| private static class JsonColumnMapperFactory implements ColumnMapperFactory { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/query/CustomJSONQueriesTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map; | if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
private static class JsonColumnMapperFactory implements ColumnMapperFactory {
@Override
public ColumnMapper build(String name, Class<?> paramType) {
return new JsonColumnMapper(name, paramType);
}
@Override
public int order() {
return 0;
}
@Override
public boolean accept(Class<?> paramType, Annotation[] annotations) {
return containAsJsonAnnotation(annotations);
}
@Override
public RowMapper<Object> getSingleColumnRowMapper(final Class<Object> clzz) {
return (resultSet, rowNum) -> JSON.fromJson(resultSet.getString(1), clzz);
}
}
| // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/query/CustomJSONQueriesTest.java
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
private static class JsonColumnMapperFactory implements ColumnMapperFactory {
@Override
public ColumnMapper build(String name, Class<?> paramType) {
return new JsonColumnMapper(name, paramType);
}
@Override
public int order() {
return 0;
}
@Override
public boolean accept(Class<?> paramType, Annotation[] annotations) {
return containAsJsonAnnotation(annotations);
}
@Override
public RowMapper<Object> getSingleColumnRowMapper(final Class<Object> clzz) {
return (resultSet, rowNum) -> JSON.fromJson(resultSet.getString(1), clzz);
}
}
| private static class JsonParameterConverter implements ParameterConverter.AdvancedParameterConverter { |
digitalfondue/npjt-extra | src/main/java/ch/digitalfondue/npjt/QueryType.java | // Path: src/main/java/ch/digitalfondue/npjt/QueryFactory.java
// static class QueryTypeAndQuery {
// final QueryType type;
// final String query;
// final Class<?> rowMapperClass;
//
// QueryTypeAndQuery(QueryType type, String query, Class<?> rowMapperClass) {
// this.type = type;
// this.query = query;
// this.rowMapperClass = rowMapperClass;
// }
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
import ch.digitalfondue.npjt.QueryFactory.QueryTypeAndQuery;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
/**
* Query Type:
*
* <ul>
* <li>TEMPLATE : we receive the string defined in @Query/@QueryOverride
* annotation.
* <li>EXECUTE : the query will be executed. If it's a select, the result will
* be mapped with a ConstructorAnnotationRowMapper if it has the correct form.
* </ul>
*
*/
public enum QueryType {
/**
* Receive the string defined in @Query/@QueryOverride annotation.
*/
TEMPLATE {
@Override | // Path: src/main/java/ch/digitalfondue/npjt/QueryFactory.java
// static class QueryTypeAndQuery {
// final QueryType type;
// final String query;
// final Class<?> rowMapperClass;
//
// QueryTypeAndQuery(QueryType type, String query, Class<?> rowMapperClass) {
// this.type = type;
// this.query = query;
// this.rowMapperClass = rowMapperClass;
// }
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/main/java/ch/digitalfondue/npjt/QueryType.java
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
import ch.digitalfondue.npjt.QueryFactory.QueryTypeAndQuery;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
/**
* Query Type:
*
* <ul>
* <li>TEMPLATE : we receive the string defined in @Query/@QueryOverride
* annotation.
* <li>EXECUTE : the query will be executed. If it's a select, the result will
* be mapped with a ConstructorAnnotationRowMapper if it has the correct form.
* </ul>
*
*/
public enum QueryType {
/**
* Receive the string defined in @Query/@QueryOverride annotation.
*/
TEMPLATE {
@Override | String apply(QueryTypeAndQuery queryTypeAndQuery, NamedParameterJdbcTemplate jdbc, |
digitalfondue/npjt-extra | src/main/java/ch/digitalfondue/npjt/QueryType.java | // Path: src/main/java/ch/digitalfondue/npjt/QueryFactory.java
// static class QueryTypeAndQuery {
// final QueryType type;
// final String query;
// final Class<?> rowMapperClass;
//
// QueryTypeAndQuery(QueryType type, String query, Class<?> rowMapperClass) {
// this.type = type;
// this.query = query;
// this.rowMapperClass = rowMapperClass;
// }
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
import ch.digitalfondue.npjt.QueryFactory.QueryTypeAndQuery;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
/**
* Query Type:
*
* <ul>
* <li>TEMPLATE : we receive the string defined in @Query/@QueryOverride
* annotation.
* <li>EXECUTE : the query will be executed. If it's a select, the result will
* be mapped with a ConstructorAnnotationRowMapper if it has the correct form.
* </ul>
*
*/
public enum QueryType {
/**
* Receive the string defined in @Query/@QueryOverride annotation.
*/
TEMPLATE {
@Override
String apply(QueryTypeAndQuery queryTypeAndQuery, NamedParameterJdbcTemplate jdbc,
Method method, Object[] args, | // Path: src/main/java/ch/digitalfondue/npjt/QueryFactory.java
// static class QueryTypeAndQuery {
// final QueryType type;
// final String query;
// final Class<?> rowMapperClass;
//
// QueryTypeAndQuery(QueryType type, String query, Class<?> rowMapperClass) {
// this.type = type;
// this.query = query;
// this.rowMapperClass = rowMapperClass;
// }
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/main/java/ch/digitalfondue/npjt/QueryType.java
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
import ch.digitalfondue.npjt.QueryFactory.QueryTypeAndQuery;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
/**
* Query Type:
*
* <ul>
* <li>TEMPLATE : we receive the string defined in @Query/@QueryOverride
* annotation.
* <li>EXECUTE : the query will be executed. If it's a select, the result will
* be mapped with a ConstructorAnnotationRowMapper if it has the correct form.
* </ul>
*
*/
public enum QueryType {
/**
* Receive the string defined in @Query/@QueryOverride annotation.
*/
TEMPLATE {
@Override
String apply(QueryTypeAndQuery queryTypeAndQuery, NamedParameterJdbcTemplate jdbc,
Method method, Object[] args, | SortedSet<ColumnMapperFactory> columnMapperFactories, SortedSet<ParameterConverter> parameterConverters) { |
digitalfondue/npjt-extra | src/main/java/ch/digitalfondue/npjt/QueryType.java | // Path: src/main/java/ch/digitalfondue/npjt/QueryFactory.java
// static class QueryTypeAndQuery {
// final QueryType type;
// final String query;
// final Class<?> rowMapperClass;
//
// QueryTypeAndQuery(QueryType type, String query, Class<?> rowMapperClass) {
// this.type = type;
// this.query = query;
// this.rowMapperClass = rowMapperClass;
// }
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
import ch.digitalfondue.npjt.QueryFactory.QueryTypeAndQuery;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
/**
* Query Type:
*
* <ul>
* <li>TEMPLATE : we receive the string defined in @Query/@QueryOverride
* annotation.
* <li>EXECUTE : the query will be executed. If it's a select, the result will
* be mapped with a ConstructorAnnotationRowMapper if it has the correct form.
* </ul>
*
*/
public enum QueryType {
/**
* Receive the string defined in @Query/@QueryOverride annotation.
*/
TEMPLATE {
@Override
String apply(QueryTypeAndQuery queryTypeAndQuery, NamedParameterJdbcTemplate jdbc,
Method method, Object[] args, | // Path: src/main/java/ch/digitalfondue/npjt/QueryFactory.java
// static class QueryTypeAndQuery {
// final QueryType type;
// final String query;
// final Class<?> rowMapperClass;
//
// QueryTypeAndQuery(QueryType type, String query, Class<?> rowMapperClass) {
// this.type = type;
// this.query = query;
// this.rowMapperClass = rowMapperClass;
// }
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/main/java/ch/digitalfondue/npjt/QueryType.java
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
import ch.digitalfondue.npjt.QueryFactory.QueryTypeAndQuery;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
/**
* Query Type:
*
* <ul>
* <li>TEMPLATE : we receive the string defined in @Query/@QueryOverride
* annotation.
* <li>EXECUTE : the query will be executed. If it's a select, the result will
* be mapped with a ConstructorAnnotationRowMapper if it has the correct form.
* </ul>
*
*/
public enum QueryType {
/**
* Receive the string defined in @Query/@QueryOverride annotation.
*/
TEMPLATE {
@Override
String apply(QueryTypeAndQuery queryTypeAndQuery, NamedParameterJdbcTemplate jdbc,
Method method, Object[] args, | SortedSet<ColumnMapperFactory> columnMapperFactories, SortedSet<ParameterConverter> parameterConverters) { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/mapper/DefaultMapperTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/DefaultMapper.java
// public class DefaultMapper extends ColumnMapper {
//
// private static final int ORDER = Integer.MAX_VALUE;
//
// public DefaultMapper(String name, Class<?> paramType) {
// super(name, paramType);
// }
//
// public Object getObject(ResultSet rs) throws SQLException {
// int columnIdx = rs.findColumn(name);
// return JdbcUtils.getResultSetValue(rs, columnIdx, paramType);
// }
//
// public static class Converter implements ParameterConverter {
//
// @Override
// public boolean accept(Class<?> parameterType, Annotation[] annotations) {
// return true;
// }
//
// @Override
// public void processParameter(String parameterName, Object arg,
// Class<?> parameterType, MapSqlParameterSource ps) {
// ps.addValue(parameterName, arg, StatementCreatorUtils.javaTypeToSqlParameterType(parameterType));
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// }
//
//
// public static class Factory implements ColumnMapperFactory {
//
// @Override
// public ColumnMapper build(String name, Class<?> paramType) {
// return new DefaultMapper(name, paramType);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// @Override
// public boolean accept(Class<?> paramType, Annotation[] annotations) {
// return true;
// }
//
// @Override
// public RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz) {
// return new SingleColumnRowMapper<>(clzz);
// }
//
// }
// }
| import static org.mockito.Mockito.when;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ch.digitalfondue.npjt.mapper.DefaultMapper; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.mapper;
@RunWith(MockitoJUnitRunner.class)
public class DefaultMapperTest {
@Mock
ResultSet resultSet;
@Test
public void testNull() throws SQLException { | // Path: src/main/java/ch/digitalfondue/npjt/mapper/DefaultMapper.java
// public class DefaultMapper extends ColumnMapper {
//
// private static final int ORDER = Integer.MAX_VALUE;
//
// public DefaultMapper(String name, Class<?> paramType) {
// super(name, paramType);
// }
//
// public Object getObject(ResultSet rs) throws SQLException {
// int columnIdx = rs.findColumn(name);
// return JdbcUtils.getResultSetValue(rs, columnIdx, paramType);
// }
//
// public static class Converter implements ParameterConverter {
//
// @Override
// public boolean accept(Class<?> parameterType, Annotation[] annotations) {
// return true;
// }
//
// @Override
// public void processParameter(String parameterName, Object arg,
// Class<?> parameterType, MapSqlParameterSource ps) {
// ps.addValue(parameterName, arg, StatementCreatorUtils.javaTypeToSqlParameterType(parameterType));
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// }
//
//
// public static class Factory implements ColumnMapperFactory {
//
// @Override
// public ColumnMapper build(String name, Class<?> paramType) {
// return new DefaultMapper(name, paramType);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// @Override
// public boolean accept(Class<?> paramType, Annotation[] annotations) {
// return true;
// }
//
// @Override
// public RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz) {
// return new SingleColumnRowMapper<>(clzz);
// }
//
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/mapper/DefaultMapperTest.java
import static org.mockito.Mockito.when;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ch.digitalfondue.npjt.mapper.DefaultMapper;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.mapper;
@RunWith(MockitoJUnitRunner.class)
public class DefaultMapperTest {
@Mock
ResultSet resultSet;
@Test
public void testNull() throws SQLException { | DefaultMapper m = new DefaultMapper("PARAM", String.class); |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/mapper/EnumMapperTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/EnumMapper.java
// public class EnumMapper extends ColumnMapper {
//
// private static final int ORDER = Integer.MAX_VALUE - 1;
//
//
// public EnumMapper(String name, Class<?> paramType) {
// super(name, paramType);
// }
//
//
// @Override
// public Object getObject(ResultSet rs) throws SQLException {
// String res = rs.getString(name);
// return toEnum(res, paramType);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// private static Object toEnum(String res, Class<?> paramType) {
// Class<? extends Enum> enumType = (Class<? extends Enum<?>>) paramType;
// return res == null ? null : Enum.valueOf(enumType, res.trim());
// }
//
// public static class Converter implements ParameterConverter {
//
// @Override
// public boolean accept(Class<?> parameterType, Annotation[] annotations) {
// return parameterType.isEnum();
// }
//
// @Override
// public void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// ps.addValue(parameterName, arg == null ? null : ((Enum<?>)arg).name());
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// }
//
//
// public static class Factory implements ColumnMapperFactory {
//
// @Override
// public ColumnMapper build(String name, Class<?> paramType) {
// return new EnumMapper(name, paramType);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// @Override
// public boolean accept(Class<?> paramType, Annotation[] annotations) {
// return paramType.isEnum();
// }
//
// @Override
// public RowMapper<Object> getSingleColumnRowMapper(final Class<Object> clazz) {
// return (rs, rowNum) -> toEnum(rs.getString(1), clazz);
// }
// }
// }
| import static org.mockito.Mockito.when;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ch.digitalfondue.npjt.mapper.EnumMapper; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.mapper;
@RunWith(MockitoJUnitRunner.class)
public class EnumMapperTest {
public enum MyEnum {
BLA, TEST;
}
@Mock
ResultSet resultSet;
@Test
public void testNull() throws SQLException { | // Path: src/main/java/ch/digitalfondue/npjt/mapper/EnumMapper.java
// public class EnumMapper extends ColumnMapper {
//
// private static final int ORDER = Integer.MAX_VALUE - 1;
//
//
// public EnumMapper(String name, Class<?> paramType) {
// super(name, paramType);
// }
//
//
// @Override
// public Object getObject(ResultSet rs) throws SQLException {
// String res = rs.getString(name);
// return toEnum(res, paramType);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// private static Object toEnum(String res, Class<?> paramType) {
// Class<? extends Enum> enumType = (Class<? extends Enum<?>>) paramType;
// return res == null ? null : Enum.valueOf(enumType, res.trim());
// }
//
// public static class Converter implements ParameterConverter {
//
// @Override
// public boolean accept(Class<?> parameterType, Annotation[] annotations) {
// return parameterType.isEnum();
// }
//
// @Override
// public void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// ps.addValue(parameterName, arg == null ? null : ((Enum<?>)arg).name());
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// }
//
//
// public static class Factory implements ColumnMapperFactory {
//
// @Override
// public ColumnMapper build(String name, Class<?> paramType) {
// return new EnumMapper(name, paramType);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// @Override
// public boolean accept(Class<?> paramType, Annotation[] annotations) {
// return paramType.isEnum();
// }
//
// @Override
// public RowMapper<Object> getSingleColumnRowMapper(final Class<Object> clazz) {
// return (rs, rowNum) -> toEnum(rs.getString(1), clazz);
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/mapper/EnumMapperTest.java
import static org.mockito.Mockito.when;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ch.digitalfondue.npjt.mapper.EnumMapper;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.mapper;
@RunWith(MockitoJUnitRunner.class)
public class EnumMapperTest {
public enum MyEnum {
BLA, TEST;
}
@Mock
ResultSet resultSet;
@Test
public void testNull() throws SQLException { | EnumMapper m = new EnumMapper("PARAM", MyEnum.class); |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/query/customfactory/CustomJSONQueriesWithCustomQueryFactoryTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*; | /**
* Copyright © 2019 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.query.customfactory;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class, CustomJSONQueriesWithCustomQueryFactoryTest.CustomQueryFactoryConf.class})
public class CustomJSONQueriesWithCustomQueryFactoryTest {
@Autowired
JsonQueries jq;
private static Gson JSON = new GsonBuilder().create();
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
| // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/query/customfactory/CustomJSONQueriesWithCustomQueryFactoryTest.java
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
/**
* Copyright © 2019 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.query.customfactory;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class, CustomJSONQueriesWithCustomQueryFactoryTest.CustomQueryFactoryConf.class})
public class CustomJSONQueriesWithCustomQueryFactoryTest {
@Autowired
JsonQueries jq;
private static Gson JSON = new GsonBuilder().create();
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
| private static class JsonColumnMapper extends ColumnMapper { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/query/customfactory/CustomJSONQueriesWithCustomQueryFactoryTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*; |
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
private static class JsonColumnMapper extends ColumnMapper {
JsonColumnMapper(String name, Class<?> paramType) {
super(name, paramType);
}
@Override
public Object getObject(ResultSet rs) throws SQLException {
return JSON.fromJson(rs.getString(name), paramType);
}
}
private static boolean containAsJsonAnnotation(Annotation[] annotations) {
if(annotations == null) {
return false;
}
for(Annotation annotation : annotations) {
if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
| // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/query/customfactory/CustomJSONQueriesWithCustomQueryFactoryTest.java
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface AsJson {
}
private static class JsonColumnMapper extends ColumnMapper {
JsonColumnMapper(String name, Class<?> paramType) {
super(name, paramType);
}
@Override
public Object getObject(ResultSet rs) throws SQLException {
return JSON.fromJson(rs.getString(name), paramType);
}
}
private static boolean containAsJsonAnnotation(Annotation[] annotations) {
if(annotations == null) {
return false;
}
for(Annotation annotation : annotations) {
if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
| private static class JsonColumnMapperFactory implements ColumnMapperFactory { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/query/customfactory/CustomJSONQueriesWithCustomQueryFactoryTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
| import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*; | if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
private static class JsonColumnMapperFactory implements ColumnMapperFactory {
@Override
public ColumnMapper build(String name, Class<?> paramType) {
return new JsonColumnMapper(name, paramType);
}
@Override
public int order() {
return 0;
}
@Override
public boolean accept(Class<?> paramType, Annotation[] annotations) {
return containAsJsonAnnotation(annotations);
}
@Override
public RowMapper<Object> getSingleColumnRowMapper(final Class<Object> clzz) {
return (resultSet, rowNum) -> JSON.fromJson(resultSet.getString(1), clzz);
}
}
| // Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapper.java
// public abstract class ColumnMapper {
//
// protected final String name;
// protected final Class<?> paramType;
//
// public ColumnMapper(String name, Class<?> paramType) {
// this.name = name;
// this.paramType = paramType;
// }
//
// public abstract Object getObject(ResultSet rs) throws SQLException;
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ColumnMapperFactory.java
// public interface ColumnMapperFactory {
// ColumnMapper build(String name, Class<?> paramType);
// int order();
// boolean accept(Class<?> paramType, Annotation[] annotations);
// RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz);
// }
//
// Path: src/main/java/ch/digitalfondue/npjt/mapper/ParameterConverter.java
// public interface ParameterConverter {
//
// boolean accept(Class<?> parameterType, Annotation[] annotations);
//
//
// interface AdvancedParameterConverter extends ParameterConverter {
// void processParameter(ProcessParameterContext processParameterContext);
//
// @Override
// default void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// throw new IllegalStateException("should not be executed");
// }
// }
//
// /**
// *
// *
// * @param parameterName
// * @param arg
// * @param parameterType
// * @param ps
// */
// void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps);
//
// int order();
//
// class ProcessParameterContext {
// private final NamedParameterJdbcTemplate jdbc;
// private final String parameterName;
// private final Class<?> parameterType;
// private final Annotation[] parameterAnnotations;
// private final Object arg;
// private final MapSqlParameterSource ps;
//
// public ProcessParameterContext(NamedParameterJdbcTemplate jdbc, String parameterName, Object arg, Class<?> parameterType, Annotation[] parameterAnnotations, MapSqlParameterSource ps) {
// this.jdbc = jdbc;
// this.parameterName = parameterName;
// this.arg = arg;
// this.parameterType = parameterType;
// this.parameterAnnotations = parameterAnnotations;
// this.ps = ps;
// }
//
// public NamedParameterJdbcTemplate getJdbc() {
// return jdbc;
// }
//
// public Connection getConnection() {
// return DataSourceUtils.getConnection(jdbc.getJdbcTemplate().getDataSource());
// }
//
// public Class<?> getParameterType() {
// return parameterType;
// }
//
// public Annotation[] getParameterAnnotations() {
// return parameterAnnotations;
// }
//
// public Object getArg() {
// return arg;
// }
//
// public String getParameterName() {
// return parameterName;
// }
//
// public MapSqlParameterSource getParameterSource() {
// return ps;
// }
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/query/customfactory/CustomJSONQueriesWithCustomQueryFactoryTest.java
import ch.digitalfondue.npjt.*;
import ch.digitalfondue.npjt.mapper.ColumnMapper;
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.lang.annotation.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
if(annotation.annotationType() == AsJson.class) {
return true;
}
}
return false;
}
private static class JsonColumnMapperFactory implements ColumnMapperFactory {
@Override
public ColumnMapper build(String name, Class<?> paramType) {
return new JsonColumnMapper(name, paramType);
}
@Override
public int order() {
return 0;
}
@Override
public boolean accept(Class<?> paramType, Annotation[] annotations) {
return containAsJsonAnnotation(annotations);
}
@Override
public RowMapper<Object> getSingleColumnRowMapper(final Class<Object> clzz) {
return (resultSet, rowNum) -> JSON.fromJson(resultSet.getString(1), clzz);
}
}
| private static class JsonParameterConverter implements ParameterConverter { |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/QueryRepositoryScannerTest.java | // Path: src/test/java/ch/digitalfondue/npjt/query/QueryRepo.java
// @QueryRepository
// public interface QueryRepo {
//
// }
//
// Path: src/test/java/ch/digitalfondue/npjt/query/deeper/QueryRepo2.java
// @QueryRepository
// public interface QueryRepo2 {
//
// }
| import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import ch.digitalfondue.npjt.query.QueryRepo;
import ch.digitalfondue.npjt.query.deeper.QueryRepo2; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class, QueryScannerConfiguration.class})
public class QueryRepositoryScannerTest {
@Autowired | // Path: src/test/java/ch/digitalfondue/npjt/query/QueryRepo.java
// @QueryRepository
// public interface QueryRepo {
//
// }
//
// Path: src/test/java/ch/digitalfondue/npjt/query/deeper/QueryRepo2.java
// @QueryRepository
// public interface QueryRepo2 {
//
// }
// Path: src/test/java/ch/digitalfondue/npjt/QueryRepositoryScannerTest.java
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import ch.digitalfondue.npjt.query.QueryRepo;
import ch.digitalfondue.npjt.query.deeper.QueryRepo2;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class, QueryScannerConfiguration.class})
public class QueryRepositoryScannerTest {
@Autowired | QueryRepo queryRepo; |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/QueryRepositoryScannerTest.java | // Path: src/test/java/ch/digitalfondue/npjt/query/QueryRepo.java
// @QueryRepository
// public interface QueryRepo {
//
// }
//
// Path: src/test/java/ch/digitalfondue/npjt/query/deeper/QueryRepo2.java
// @QueryRepository
// public interface QueryRepo2 {
//
// }
| import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import ch.digitalfondue.npjt.query.QueryRepo;
import ch.digitalfondue.npjt.query.deeper.QueryRepo2; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class, QueryScannerConfiguration.class})
public class QueryRepositoryScannerTest {
@Autowired
QueryRepo queryRepo;
@Autowired | // Path: src/test/java/ch/digitalfondue/npjt/query/QueryRepo.java
// @QueryRepository
// public interface QueryRepo {
//
// }
//
// Path: src/test/java/ch/digitalfondue/npjt/query/deeper/QueryRepo2.java
// @QueryRepository
// public interface QueryRepo2 {
//
// }
// Path: src/test/java/ch/digitalfondue/npjt/QueryRepositoryScannerTest.java
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import ch.digitalfondue.npjt.query.QueryRepo;
import ch.digitalfondue.npjt.query.deeper.QueryRepo2;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestJdbcConfiguration.class, QueryScannerConfiguration.class})
public class QueryRepositoryScannerTest {
@Autowired
QueryRepo queryRepo;
@Autowired | QueryRepo2 queryRepo2; |
digitalfondue/npjt-extra | src/test/java/ch/digitalfondue/npjt/mapper/ZonedDateTimeMapperTest.java | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ZonedDateTimeMapper.java
// public class ZonedDateTimeMapper extends ColumnMapper {
//
// private static final int ORDER = Integer.MAX_VALUE -2;
//
// private static final TimeZone UTC_TZ = TimeZone.getTimeZone("UTC");
// private static final ZoneId UTC_Z_ID = ZoneId.of("UTC");
//
// public ZonedDateTimeMapper(String name, Class<?> paramType) {
// super(name, paramType);
// }
//
// public Object getObject(ResultSet rs) throws SQLException {
// Timestamp timestamp = rs.getTimestamp(name, Calendar.getInstance(UTC_TZ));
// return toZonedDateTime(timestamp);
// }
//
// private static Object toZonedDateTime(Timestamp timestamp) {
// if (timestamp == null) {
// return null;
// }
// return ZonedDateTime.ofInstant(timestamp.toInstant(), UTC_Z_ID);
// }
//
// public static class Converter implements ParameterConverter {
//
// @Override
// public boolean accept(Class<?> parameterType, Annotation[] annotations) {
// return ZonedDateTime.class.isAssignableFrom(parameterType);
// }
//
// @Override
// public void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// Calendar c = null;
// if(arg != null) {
// ZonedDateTime dateTime = ZonedDateTime.class.cast(arg);
// ZonedDateTime utc = dateTime.withZoneSameInstant(UTC_Z_ID);
// c = Calendar.getInstance();
// c.setTimeZone(UTC_TZ);
// c.setTimeInMillis(utc.toInstant().toEpochMilli());
// }
// ps.addValue(parameterName, c, Types.TIMESTAMP);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// }
//
//
//
// public static class Factory implements ColumnMapperFactory {
//
// @Override
// public ColumnMapper build(String name, Class<?> paramType) {
// return new ZonedDateTimeMapper(name, paramType);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// @Override
// public boolean accept(Class<?> paramType, Annotation[] annotations) {
// return ZonedDateTime.class.isAssignableFrom(paramType);
// }
//
// @Override
// public RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz) {
// return (rs, rowNum) -> {
// Timestamp timestamp = rs.getTimestamp(1, Calendar.getInstance(UTC_TZ));
// return toZonedDateTime(timestamp);
// };
// }
//
// }
// }
| import static org.mockito.Mockito.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.ZonedDateTime;
import java.util.Calendar;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ch.digitalfondue.npjt.mapper.ZonedDateTimeMapper; | /**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.mapper;
@RunWith(MockitoJUnitRunner.class)
public class ZonedDateTimeMapperTest {
@Mock
ResultSet resultSet;
@Test
public void testNull() throws SQLException { | // Path: src/main/java/ch/digitalfondue/npjt/mapper/ZonedDateTimeMapper.java
// public class ZonedDateTimeMapper extends ColumnMapper {
//
// private static final int ORDER = Integer.MAX_VALUE -2;
//
// private static final TimeZone UTC_TZ = TimeZone.getTimeZone("UTC");
// private static final ZoneId UTC_Z_ID = ZoneId.of("UTC");
//
// public ZonedDateTimeMapper(String name, Class<?> paramType) {
// super(name, paramType);
// }
//
// public Object getObject(ResultSet rs) throws SQLException {
// Timestamp timestamp = rs.getTimestamp(name, Calendar.getInstance(UTC_TZ));
// return toZonedDateTime(timestamp);
// }
//
// private static Object toZonedDateTime(Timestamp timestamp) {
// if (timestamp == null) {
// return null;
// }
// return ZonedDateTime.ofInstant(timestamp.toInstant(), UTC_Z_ID);
// }
//
// public static class Converter implements ParameterConverter {
//
// @Override
// public boolean accept(Class<?> parameterType, Annotation[] annotations) {
// return ZonedDateTime.class.isAssignableFrom(parameterType);
// }
//
// @Override
// public void processParameter(String parameterName, Object arg, Class<?> parameterType, MapSqlParameterSource ps) {
// Calendar c = null;
// if(arg != null) {
// ZonedDateTime dateTime = ZonedDateTime.class.cast(arg);
// ZonedDateTime utc = dateTime.withZoneSameInstant(UTC_Z_ID);
// c = Calendar.getInstance();
// c.setTimeZone(UTC_TZ);
// c.setTimeInMillis(utc.toInstant().toEpochMilli());
// }
// ps.addValue(parameterName, c, Types.TIMESTAMP);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// }
//
//
//
// public static class Factory implements ColumnMapperFactory {
//
// @Override
// public ColumnMapper build(String name, Class<?> paramType) {
// return new ZonedDateTimeMapper(name, paramType);
// }
//
// @Override
// public int order() {
// return ORDER;
// }
//
// @Override
// public boolean accept(Class<?> paramType, Annotation[] annotations) {
// return ZonedDateTime.class.isAssignableFrom(paramType);
// }
//
// @Override
// public RowMapper<Object> getSingleColumnRowMapper(Class<Object> clzz) {
// return (rs, rowNum) -> {
// Timestamp timestamp = rs.getTimestamp(1, Calendar.getInstance(UTC_TZ));
// return toZonedDateTime(timestamp);
// };
// }
//
// }
// }
// Path: src/test/java/ch/digitalfondue/npjt/mapper/ZonedDateTimeMapperTest.java
import static org.mockito.Mockito.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.ZonedDateTime;
import java.util.Calendar;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import ch.digitalfondue.npjt.mapper.ZonedDateTimeMapper;
/**
* Copyright © 2015 digitalfondue (info@digitalfondue.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.digitalfondue.npjt.mapper;
@RunWith(MockitoJUnitRunner.class)
public class ZonedDateTimeMapperTest {
@Mock
ResultSet resultSet;
@Test
public void testNull() throws SQLException { | ZonedDateTimeMapper m = new ZonedDateTimeMapper("PARAM", ZonedDateTime.class); |
richardtynan/thornsec | src/singleton/IPTablesConf.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit; | package singleton;
public class IPTablesConf extends AProfile {
Hashtable<String, Hashtable<String, Vector<String>>> tables;
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/singleton/IPTablesConf.java
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit;
package singleton;
public class IPTablesConf extends AProfile {
Hashtable<String, Hashtable<String, Vector<String>>> tables;
| public SimpleUnit addFilterInput(String name, String rule) { |
richardtynan/thornsec | src/singleton/IPTablesConf.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit; |
private String getNat() {
Vector<String> chain = this.getChain("nat", "POSTROUTING");
String nat = "";
for (int i = 0; i < chain.size(); i++) {
nat += "-A POSTROUTING " + chain.elementAt(chain.size() - 1 - i) + "\n";
}
return nat;
}
private String getFilter() {
String policy = "";
String filter = "";
policy += ":INPUT ACCEPT [0:0]\n";
policy += ":FORWARD ACCEPT [0:0]\n";
policy += ":OUTPUT ACCEPT [0:0]\n";
Hashtable<String, Vector<String>> tab = tables.get("filter");
Iterator<String> iter = tab.keySet().iterator();
while (iter.hasNext()) {
String val = iter.next();
if (!val.equals("INPUT") && !val.equals("FORWARD") && !val.equals("OUTPUT"))
policy += ":" + val + " - [0:0]\n";
Vector<String> chain = this.getChain("filter", val);
for (int j = 0; j < chain.size(); j++) {
filter += "-A " + val + " " + chain.elementAt(chain.size() - j - 1) + "\n";
}
}
return policy + filter;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/singleton/IPTablesConf.java
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit;
private String getNat() {
Vector<String> chain = this.getChain("nat", "POSTROUTING");
String nat = "";
for (int i = 0; i < chain.size(); i++) {
nat += "-A POSTROUTING " + chain.elementAt(chain.size() - 1 - i) + "\n";
}
return nat;
}
private String getFilter() {
String policy = "";
String filter = "";
policy += ":INPUT ACCEPT [0:0]\n";
policy += ":FORWARD ACCEPT [0:0]\n";
policy += ":OUTPUT ACCEPT [0:0]\n";
Hashtable<String, Vector<String>> tab = tables.get("filter");
Iterator<String> iter = tab.keySet().iterator();
while (iter.hasNext()) {
String val = iter.next();
if (!val.equals("INPUT") && !val.equals("FORWARD") && !val.equals("OUTPUT"))
policy += ":" + val + " - [0:0]\n";
Vector<String> chain = this.getChain("filter", val);
for (int j = 0; j < chain.size(); j++) {
filter += "-A " + val + " " + chain.elementAt(chain.size() - j - 1) + "\n";
}
}
return policy + filter;
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/singleton/IPTablesConf.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit; |
private String getNat() {
Vector<String> chain = this.getChain("nat", "POSTROUTING");
String nat = "";
for (int i = 0; i < chain.size(); i++) {
nat += "-A POSTROUTING " + chain.elementAt(chain.size() - 1 - i) + "\n";
}
return nat;
}
private String getFilter() {
String policy = "";
String filter = "";
policy += ":INPUT ACCEPT [0:0]\n";
policy += ":FORWARD ACCEPT [0:0]\n";
policy += ":OUTPUT ACCEPT [0:0]\n";
Hashtable<String, Vector<String>> tab = tables.get("filter");
Iterator<String> iter = tab.keySet().iterator();
while (iter.hasNext()) {
String val = iter.next();
if (!val.equals("INPUT") && !val.equals("FORWARD") && !val.equals("OUTPUT"))
policy += ":" + val + " - [0:0]\n";
Vector<String> chain = this.getChain("filter", val);
for (int j = 0; j < chain.size(); j++) {
filter += "-A " + val + " " + chain.elementAt(chain.size() - j - 1) + "\n";
}
}
return policy + filter;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/singleton/IPTablesConf.java
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit;
private String getNat() {
Vector<String> chain = this.getChain("nat", "POSTROUTING");
String nat = "";
for (int i = 0; i < chain.size(); i++) {
nat += "-A POSTROUTING " + chain.elementAt(chain.size() - 1 - i) + "\n";
}
return nat;
}
private String getFilter() {
String policy = "";
String filter = "";
policy += ":INPUT ACCEPT [0:0]\n";
policy += ":FORWARD ACCEPT [0:0]\n";
policy += ":OUTPUT ACCEPT [0:0]\n";
Hashtable<String, Vector<String>> tab = tables.get("filter");
Iterator<String> iter = tab.keySet().iterator();
while (iter.hasNext()) {
String val = iter.next();
if (!val.equals("INPUT") && !val.equals("FORWARD") && !val.equals("OUTPUT"))
policy += ":" + val + " - [0:0]\n";
Vector<String> chain = this.getChain("filter", val);
for (int j = 0; j < chain.size(); j++) {
filter += "-A " + val + " " + chain.elementAt(chain.size() - j - 1) + "\n";
}
}
return policy + filter;
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/core/view/SimpleFrame.java | // Path: src/core/model/OrgsecModel.java
// public class OrgsecModel {
//
// private OrgsecData data;
//
// private HashMap<String, NetworkModel> networks;
//
// public void setData(OrgsecData data) {
// this.data = data;
// networks = new HashMap<String, NetworkModel>();
// String[] netlabs = data.getNetworkLabels();
// for (int i = 0; i < netlabs.length; i++) {
// NetworkModel mod = new NetworkModel();
// mod.setData(data.getNetworkData(netlabs[i]));
// networks.put(netlabs[i], mod);
// }
// }
//
// public String[] getNetworkLabels() {
// return data.getNetworkLabels();
// }
//
// public NetworkModel getNetworkModel(String label) {
// return networks.get(label);
// }
//
// }
| import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.text.DefaultCaret;
import core.model.OrgsecModel; | package core.view;
public class SimpleFrame {
private JTabbedPane jtp; | // Path: src/core/model/OrgsecModel.java
// public class OrgsecModel {
//
// private OrgsecData data;
//
// private HashMap<String, NetworkModel> networks;
//
// public void setData(OrgsecData data) {
// this.data = data;
// networks = new HashMap<String, NetworkModel>();
// String[] netlabs = data.getNetworkLabels();
// for (int i = 0; i < netlabs.length; i++) {
// NetworkModel mod = new NetworkModel();
// mod.setData(data.getNetworkData(netlabs[i]));
// networks.put(netlabs[i], mod);
// }
// }
//
// public String[] getNetworkLabels() {
// return data.getNetworkLabels();
// }
//
// public NetworkModel getNetworkModel(String label) {
// return networks.get(label);
// }
//
// }
// Path: src/core/view/SimpleFrame.java
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.text.DefaultCaret;
import core.model.OrgsecModel;
package core.view;
public class SimpleFrame {
private JTabbedPane jtp; | private OrgsecModel model; |
richardtynan/thornsec | src/profile/Service.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile; | package profile;
public class Service extends AStructuredProfile {
public Service() {
super("server");
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
// Path: src/profile/Service.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
package profile;
public class Service extends AStructuredProfile {
public Service() {
super("server");
}
| public Vector<IProfile> getInstalled(String server, INetworkData data) { |
richardtynan/thornsec | src/profile/Service.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile; | package profile;
public class Service extends AStructuredProfile {
public Service() {
super("server");
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
// Path: src/profile/Service.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
package profile;
public class Service extends AStructuredProfile {
public Service() {
super("server");
}
| public Vector<IProfile> getInstalled(String server, INetworkData data) { |
richardtynan/thornsec | src/core/profile/CompoundProfile.java | // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
| import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit; | package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config; | // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
// Path: src/core/profile/CompoundProfile.java
import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit;
package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config; | private Vector<IProfile> children; |
richardtynan/thornsec | src/core/profile/CompoundProfile.java | // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
| import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit; | package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config;
private Vector<IProfile> children;
public CompoundProfile(String name, String precondition, String config) {
super(name);
this.precondition = precondition;
this.config = config;
this.children = new Vector<IProfile>();
}
| // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
// Path: src/core/profile/CompoundProfile.java
import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit;
package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config;
private Vector<IProfile> children;
public CompoundProfile(String name, String precondition, String config) {
super(name);
this.precondition = precondition;
this.config = config;
this.children = new Vector<IProfile>();
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/core/profile/CompoundProfile.java | // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
| import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit; | package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config;
private Vector<IProfile> children;
public CompoundProfile(String name, String precondition, String config) {
super(name);
this.precondition = precondition;
this.config = config;
this.children = new Vector<IProfile>();
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> rules = new Vector<IProfile>(); | // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
// Path: src/core/profile/CompoundProfile.java
import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit;
package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config;
private Vector<IProfile> children;
public CompoundProfile(String name, String precondition, String config) {
super(name);
this.precondition = precondition;
this.config = config;
this.children = new Vector<IProfile>();
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> rules = new Vector<IProfile>(); | rules.add(new ComplexUnit(getLabel() + "_compound", precondition, "", |
richardtynan/thornsec | src/core/profile/CompoundProfile.java | // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
| import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit; | package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config;
private Vector<IProfile> children;
public CompoundProfile(String name, String precondition, String config) {
super(name);
this.precondition = precondition;
this.config = config;
this.children = new Vector<IProfile>();
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> rules = new Vector<IProfile>();
rules.add(new ComplexUnit(getLabel() + "_compound", precondition, "",
getLabel() + "_unchanged=1;\n" + getLabel() + "_compound=1;\n"));
rules.addAll(this.children);
rules.add(new ComplexUnit(getLabel(), precondition, config + "\n" + getLabel() + "_unchanged=1;\n",
getLabel() + "=$" + getLabel() + "_unchanged;\n"));
return rules;
}
| // Path: src/core/iface/IChildUnit.java
// public interface IChildUnit extends IUnit {
//
// public String getParent();
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/unit/ComplexUnit.java
// public class ComplexUnit extends ASingleUnit {
//
// protected ComplexUnit() {
// }
//
// public ComplexUnit(String label, String precondition, String config, String audit) {
// super(label, precondition, config, audit);
// }
//
// protected String getAudit() {
// return this.audit;
// }
//
// protected String getPrecondition() {
// return precondition;
// }
//
// protected String getConfig() {
// return config;
// }
//
// protected String getDryRun() {
// return "";
// }
//
// }
// Path: src/core/profile/CompoundProfile.java
import java.util.Vector;
import core.iface.IChildUnit;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.unit.ComplexUnit;
package core.profile;
public class CompoundProfile extends AProfile {
private String precondition;
private String config;
private Vector<IProfile> children;
public CompoundProfile(String name, String precondition, String config) {
super(name);
this.precondition = precondition;
this.config = config;
this.children = new Vector<IProfile>();
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> rules = new Vector<IProfile>();
rules.add(new ComplexUnit(getLabel() + "_compound", precondition, "",
getLabel() + "_unchanged=1;\n" + getLabel() + "_compound=1;\n"));
rules.addAll(this.children);
rules.add(new ComplexUnit(getLabel(), precondition, config + "\n" + getLabel() + "_unchanged=1;\n",
getLabel() + "=$" + getLabel() + "_unchanged;\n"));
return rules;
}
| public void addChild(IChildUnit rule) { |
richardtynan/thornsec | src/core/profile/AStructuredProfile.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile; | package core.profile;
public abstract class AStructuredProfile extends AProfile {
protected AStructuredProfile(String name) {
super(name);
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
// Path: src/core/profile/AStructuredProfile.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
package core.profile;
public abstract class AStructuredProfile extends AProfile {
protected AStructuredProfile(String name) {
super(name);
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/core/profile/AStructuredProfile.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile; | package core.profile;
public abstract class AStructuredProfile extends AProfile {
protected AStructuredProfile(String name) {
super(name);
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
// Path: src/core/profile/AStructuredProfile.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
package core.profile;
public abstract class AStructuredProfile extends AProfile {
protected AStructuredProfile(String name) {
super(name);
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/profile/Metal.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
import unit.pkg.InstalledUnit; | package profile;
public class Metal extends AStructuredProfile {
public Metal() {
super("metal");
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
// Path: src/profile/Metal.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
import unit.pkg.InstalledUnit;
package profile;
public class Metal extends AStructuredProfile {
public Metal() {
super("metal");
}
| public Vector<IProfile> getInstalled(String server, INetworkData data) { |
richardtynan/thornsec | src/profile/Metal.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
import unit.pkg.InstalledUnit; | package profile;
public class Metal extends AStructuredProfile {
public Metal() {
super("metal");
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
// Path: src/profile/Metal.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
import unit.pkg.InstalledUnit;
package profile;
public class Metal extends AStructuredProfile {
public Metal() {
super("metal");
}
| public Vector<IProfile> getInstalled(String server, INetworkData data) { |
richardtynan/thornsec | src/profile/Metal.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
import unit.pkg.InstalledUnit; | package profile;
public class Metal extends AStructuredProfile {
public Metal() {
super("metal");
}
public Vector<IProfile> getInstalled(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>(); | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AStructuredProfile.java
// public abstract class AStructuredProfile extends AProfile {
//
// protected AStructuredProfile(String name) {
// super(name);
// }
//
// public Vector<IProfile> getUnits(String server, INetworkData data) {
// Vector<IProfile> children = new Vector<IProfile>();
// children.addAll(this.getInstalled(server, data));
// children.addAll(this.getPersistent(server, data));
// children.addAll(this.getIpt(server, data));
// children.addAll(this.getLive(server, data));
// return children;
// }
//
// protected abstract Vector<IProfile> getInstalled(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getPersistent(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getIpt(String server, INetworkData data);
//
// protected abstract Vector<IProfile> getLive(String server, INetworkData data);
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
// Path: src/profile/Metal.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AStructuredProfile;
import unit.pkg.InstalledUnit;
package profile;
public class Metal extends AStructuredProfile {
public Metal() {
super("metal");
}
public Vector<IProfile> getInstalled(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>(); | vec.addElement(new InstalledUnit("metal_virtualbox", "virtualbox")); |
richardtynan/thornsec | src/singleton/NetConf.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.util.Hashtable;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit; | package singleton;
public class NetConf extends AProfile {
Vector<String> strings;
public boolean isSingleton() {
return true;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/singleton/NetConf.java
import java.util.Hashtable;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit;
package singleton;
public class NetConf extends AProfile {
Vector<String> strings;
public boolean isSingleton() {
return true;
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/singleton/NetConf.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.util.Hashtable;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit; | package singleton;
public class NetConf extends AProfile {
Vector<String> strings;
public boolean isSingleton() {
return true;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/singleton/NetConf.java
import java.util.Hashtable;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit;
package singleton;
public class NetConf extends AProfile {
Vector<String> strings;
public boolean isSingleton() {
return true;
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/singleton/NetConf.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.util.Hashtable;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit; | package singleton;
public class NetConf extends AProfile {
Vector<String> strings;
public boolean isSingleton() {
return true;
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>(); | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/singleton/NetConf.java
import java.util.Hashtable;
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import core.unit.SimpleUnit;
package singleton;
public class NetConf extends AProfile {
Vector<String> strings;
public boolean isSingleton() {
return true;
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>(); | vec.addElement(new SimpleUnit("net_conf_persist", "proceed", |
richardtynan/thornsec | src/core/Test.java | // Path: src/core/data/OrgsecData.java
// public class OrgsecData extends AData {
//
// private HashMap<String, NetworkData> networks;
//
// public OrgsecData() {
// super("orgsec");
// }
//
// public void read(JSONObject nets) {
// networks = new HashMap<String, NetworkData>();
// Iterator<?> iter = nets.keySet().iterator();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// NetworkData net = new NetworkData(key);
// net.read(nets.get(key).toString());
// networks.put(key, net);
// }
// }
//
// public String[] getNetworkLabels() {
// String[] labs = new String[networks.keySet().size()];
// Iterator<?> iter = networks.keySet().iterator();
// int i = 0;
// while (iter.hasNext()) {
// String key = (String) iter.next();
// labs[i] = key;
// i++;
// }
// return labs;
// }
//
// public NetworkData getNetworkData(String label) {
// return networks.get(label);
// }
//
// }
//
// Path: src/core/model/OrgsecModel.java
// public class OrgsecModel {
//
// private OrgsecData data;
//
// private HashMap<String, NetworkModel> networks;
//
// public void setData(OrgsecData data) {
// this.data = data;
// networks = new HashMap<String, NetworkModel>();
// String[] netlabs = data.getNetworkLabels();
// for (int i = 0; i < netlabs.length; i++) {
// NetworkModel mod = new NetworkModel();
// mod.setData(data.getNetworkData(netlabs[i]));
// networks.put(netlabs[i], mod);
// }
// }
//
// public String[] getNetworkLabels() {
// return data.getNetworkLabels();
// }
//
// public NetworkModel getNetworkModel(String label) {
// return networks.get(label);
// }
//
// }
| import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import core.data.OrgsecData;
import core.model.OrgsecModel; | package core;
public class Test {
public static void main(String[] args) throws Exception {
String text = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
| // Path: src/core/data/OrgsecData.java
// public class OrgsecData extends AData {
//
// private HashMap<String, NetworkData> networks;
//
// public OrgsecData() {
// super("orgsec");
// }
//
// public void read(JSONObject nets) {
// networks = new HashMap<String, NetworkData>();
// Iterator<?> iter = nets.keySet().iterator();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// NetworkData net = new NetworkData(key);
// net.read(nets.get(key).toString());
// networks.put(key, net);
// }
// }
//
// public String[] getNetworkLabels() {
// String[] labs = new String[networks.keySet().size()];
// Iterator<?> iter = networks.keySet().iterator();
// int i = 0;
// while (iter.hasNext()) {
// String key = (String) iter.next();
// labs[i] = key;
// i++;
// }
// return labs;
// }
//
// public NetworkData getNetworkData(String label) {
// return networks.get(label);
// }
//
// }
//
// Path: src/core/model/OrgsecModel.java
// public class OrgsecModel {
//
// private OrgsecData data;
//
// private HashMap<String, NetworkModel> networks;
//
// public void setData(OrgsecData data) {
// this.data = data;
// networks = new HashMap<String, NetworkModel>();
// String[] netlabs = data.getNetworkLabels();
// for (int i = 0; i < netlabs.length; i++) {
// NetworkModel mod = new NetworkModel();
// mod.setData(data.getNetworkData(netlabs[i]));
// networks.put(netlabs[i], mod);
// }
// }
//
// public String[] getNetworkLabels() {
// return data.getNetworkLabels();
// }
//
// public NetworkModel getNetworkModel(String label) {
// return networks.get(label);
// }
//
// }
// Path: src/core/Test.java
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import core.data.OrgsecData;
import core.model.OrgsecModel;
package core;
public class Test {
public static void main(String[] args) throws Exception {
String text = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
| OrgsecData data = new OrgsecData(); |
richardtynan/thornsec | src/core/Test.java | // Path: src/core/data/OrgsecData.java
// public class OrgsecData extends AData {
//
// private HashMap<String, NetworkData> networks;
//
// public OrgsecData() {
// super("orgsec");
// }
//
// public void read(JSONObject nets) {
// networks = new HashMap<String, NetworkData>();
// Iterator<?> iter = nets.keySet().iterator();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// NetworkData net = new NetworkData(key);
// net.read(nets.get(key).toString());
// networks.put(key, net);
// }
// }
//
// public String[] getNetworkLabels() {
// String[] labs = new String[networks.keySet().size()];
// Iterator<?> iter = networks.keySet().iterator();
// int i = 0;
// while (iter.hasNext()) {
// String key = (String) iter.next();
// labs[i] = key;
// i++;
// }
// return labs;
// }
//
// public NetworkData getNetworkData(String label) {
// return networks.get(label);
// }
//
// }
//
// Path: src/core/model/OrgsecModel.java
// public class OrgsecModel {
//
// private OrgsecData data;
//
// private HashMap<String, NetworkModel> networks;
//
// public void setData(OrgsecData data) {
// this.data = data;
// networks = new HashMap<String, NetworkModel>();
// String[] netlabs = data.getNetworkLabels();
// for (int i = 0; i < netlabs.length; i++) {
// NetworkModel mod = new NetworkModel();
// mod.setData(data.getNetworkData(netlabs[i]));
// networks.put(netlabs[i], mod);
// }
// }
//
// public String[] getNetworkLabels() {
// return data.getNetworkLabels();
// }
//
// public NetworkModel getNetworkModel(String label) {
// return networks.get(label);
// }
//
// }
| import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import core.data.OrgsecData;
import core.model.OrgsecModel; | package core;
public class Test {
public static void main(String[] args) throws Exception {
String text = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
OrgsecData data = new OrgsecData();
data.read(text);
| // Path: src/core/data/OrgsecData.java
// public class OrgsecData extends AData {
//
// private HashMap<String, NetworkData> networks;
//
// public OrgsecData() {
// super("orgsec");
// }
//
// public void read(JSONObject nets) {
// networks = new HashMap<String, NetworkData>();
// Iterator<?> iter = nets.keySet().iterator();
// while (iter.hasNext()) {
// String key = (String) iter.next();
// NetworkData net = new NetworkData(key);
// net.read(nets.get(key).toString());
// networks.put(key, net);
// }
// }
//
// public String[] getNetworkLabels() {
// String[] labs = new String[networks.keySet().size()];
// Iterator<?> iter = networks.keySet().iterator();
// int i = 0;
// while (iter.hasNext()) {
// String key = (String) iter.next();
// labs[i] = key;
// i++;
// }
// return labs;
// }
//
// public NetworkData getNetworkData(String label) {
// return networks.get(label);
// }
//
// }
//
// Path: src/core/model/OrgsecModel.java
// public class OrgsecModel {
//
// private OrgsecData data;
//
// private HashMap<String, NetworkModel> networks;
//
// public void setData(OrgsecData data) {
// this.data = data;
// networks = new HashMap<String, NetworkModel>();
// String[] netlabs = data.getNetworkLabels();
// for (int i = 0; i < netlabs.length; i++) {
// NetworkModel mod = new NetworkModel();
// mod.setData(data.getNetworkData(netlabs[i]));
// networks.put(netlabs[i], mod);
// }
// }
//
// public String[] getNetworkLabels() {
// return data.getNetworkLabels();
// }
//
// public NetworkModel getNetworkModel(String label) {
// return networks.get(label);
// }
//
// }
// Path: src/core/Test.java
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import core.data.OrgsecData;
import core.model.OrgsecModel;
package core;
public class Test {
public static void main(String[] args) throws Exception {
String text = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
OrgsecData data = new OrgsecData();
data.read(text);
| OrgsecModel model = new OrgsecModel(); |
richardtynan/thornsec | src/profile/service/Apache.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit; | package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
// Path: src/profile/service/Apache.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit;
package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/profile/service/Apache.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit; | package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
// Path: src/profile/service/Apache.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit;
package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/profile/service/Apache.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit; | package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>(); | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
// Path: src/profile/service/Apache.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit;
package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>(); | vec.addElement(new InstalledUnit("apache", "apache2")); |
richardtynan/thornsec | src/profile/service/Apache.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit; | package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>();
vec.addElement(new InstalledUnit("apache", "apache2")); | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/profile/AProfile.java
// public abstract class AProfile implements IProfile {
//
// protected String name;
//
// protected AProfile(String name) {
// this.name = name;
// }
//
// public String getLabel() {
// return name;
// }
//
// public boolean isSingleton() {
// return false;
// }
//
// public static String getProperty(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// return config.get(prop).toString();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// public static String getProperties(String prop, String prof, String server, INetworkData data) {
// try {
// String val = data.getServerData(server, prof);
// JSONParser parser = new JSONParser();
// JSONObject config = (JSONObject) parser.parse(val);
// JSONArray props = (JSONArray) config.get(prop);
// String propstring = "";
// for (int i = 0; i < props.size(); i++) {
// propstring += props.get(i) + "\n";
// }
// return propstring;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// return "";
// }
//
// }
//
// Path: src/unit/pkg/InstalledUnit.java
// public class InstalledUnit extends SimpleUnit {
//
// public InstalledUnit(String name, String pkg) {
// super(name + "_installed", "proceed", "sudo apt-get update; sudo apt-get install --assume-yes " + pkg + ";",
// "dpkg-query --status " + pkg + " | grep \"Status:\";", "Status: install ok installed", "pass");
// }
//
// }
//
// Path: src/unit/pkg/RunningUnit.java
// public class RunningUnit extends SimpleUnit {
//
// public RunningUnit(String name, String pkg, String grep) {
// super(name + "_running", name + "_installed", "sudo systemctl restart " + pkg + ";",
// "ps aux | grep -v grep | grep " + grep + ";", "", "fail");
// }
//
// }
// Path: src/profile/service/Apache.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.profile.AProfile;
import unit.pkg.InstalledUnit;
import unit.pkg.RunningUnit;
package profile.service;
public class Apache extends AProfile {
public Apache() {
super("apache");
}
public Vector<IProfile> getUnits(String server, INetworkData data) {
Vector<IProfile> vec = new Vector<IProfile>();
vec.addElement(new InstalledUnit("apache", "apache2")); | vec.addElement(new RunningUnit("apache", "apache2", "apache2")); |
richardtynan/thornsec | src/core/model/NetworkModel.java | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit; | package core.model;
public class NetworkModel {
private INetworkData data;
| // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/core/model/NetworkModel.java
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit;
package core.model;
public class NetworkModel {
private INetworkData data;
| private HashMap<String, Vector<IProfile>> rules; |
richardtynan/thornsec | src/core/model/NetworkModel.java | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit; |
public String[] getDeviceMacs() {
return data.getDeviceMacs();
}
public String[] getServerProfiles(String server) {
return data.getServerProfiles(server);
}
public int getUnitCount(String server) {
return this.rules.get(server).size();
}
public void auditDummy(String server, OutputStream out, InputStream in) {
String line = getAction("audit", server);
System.out.println(line);
}
public void dryrunDummy(String server, OutputStream out, InputStream in) {
String line = getAction("dryrun", server);
System.out.println(line);
}
public void configDummy(String server, OutputStream out, InputStream in) {
String line = getAction("config", server);
System.out.println(line);
}
public void auditServer(String server, OutputStream out, InputStream in) {
String line = getAction("audit", server); | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/core/model/NetworkModel.java
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit;
public String[] getDeviceMacs() {
return data.getDeviceMacs();
}
public String[] getServerProfiles(String server) {
return data.getServerProfiles(server);
}
public int getUnitCount(String server) {
return this.rules.get(server).size();
}
public void auditDummy(String server, OutputStream out, InputStream in) {
String line = getAction("audit", server);
System.out.println(line);
}
public void dryrunDummy(String server, OutputStream out, InputStream in) {
String line = getAction("dryrun", server);
System.out.println(line);
}
public void configDummy(String server, OutputStream out, InputStream in) {
String line = getAction("config", server);
System.out.println(line);
}
public void auditServer(String server, OutputStream out, InputStream in) {
String line = getAction("audit", server); | ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server), |
richardtynan/thornsec | src/core/model/NetworkModel.java | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit; | exec.manageBlock();
}
public void dryrunServerBlock(String server, OutputStream out, InputStream in) {
String line = getAction("dryrun", server);
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
public void configServerBlock(String server, OutputStream out, InputStream in) {
String line = getAction("config", server);
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
private String getAction(String action, String server) {
System.out.println("=======================" + this.getLabel() + ":" + server + "==========================");
String line = this.getHeader(server, action) + "\n";
Vector<IProfile> serverRules = this.rules.get(server);
String configcmd = "";
if (data.getServerUpdate(server).equals("true")) {
configcmd = "sudo apt-get --assume-yes upgrade;";
} else {
configcmd = "echo \"$out\";";
} | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/core/model/NetworkModel.java
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit;
exec.manageBlock();
}
public void dryrunServerBlock(String server, OutputStream out, InputStream in) {
String line = getAction("dryrun", server);
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
public void configServerBlock(String server, OutputStream out, InputStream in) {
String line = getAction("config", server);
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
private String getAction(String action, String server) {
System.out.println("=======================" + this.getLabel() + ":" + server + "==========================");
String line = this.getHeader(server, action) + "\n";
Vector<IProfile> serverRules = this.rules.get(server);
String configcmd = "";
if (data.getServerUpdate(server).equals("true")) {
configcmd = "sudo apt-get --assume-yes upgrade;";
} else {
configcmd = "echo \"$out\";";
} | serverRules.insertElementAt(new SimpleUnit("update", "proceed", configcmd, |
richardtynan/thornsec | src/core/model/NetworkModel.java | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
| import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit; | //System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
public void configServerBlock(String server, OutputStream out, InputStream in) {
String line = getAction("config", server);
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
private String getAction(String action, String server) {
System.out.println("=======================" + this.getLabel() + ":" + server + "==========================");
String line = this.getHeader(server, action) + "\n";
Vector<IProfile> serverRules = this.rules.get(server);
String configcmd = "";
if (data.getServerUpdate(server).equals("true")) {
configcmd = "sudo apt-get --assume-yes upgrade;";
} else {
configcmd = "echo \"$out\";";
}
serverRules.insertElementAt(new SimpleUnit("update", "proceed", configcmd,
"sudo apt-get update > /dev/null; sudo apt-get --assume-no upgrade | grep \"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\";",
"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "pass"), 0);
for (int i = 0; i < serverRules.size(); i++) { | // Path: src/core/exec/ManageExec.java
// public class ManageExec {
//
// private String login;
// private String user;
// private String ip;
// private String port;
// private String cmd;
// private OutputStream out;
//
// public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// this.login = login;
// this.user = user;
// this.ip = ip;
// this.port = port;
// this.cmd = cmd;
// this.out = out;
// }
//
// public ProcessExec manage() {
// try {
// ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// exec1.writeAllClose(this.cmd.getBytes());
// exec1.waitFor();
// ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// + this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// Thread.sleep(500);
// PasswordExec pwd = new PasswordExec(login);
// String pass = pwd.getPassword() + "\n";
// exec2.writeAllOpen(pass.getBytes());
// return exec2;
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// return null;
// }
//
// public void manageBlock() {
// ProcessExec exec = manage();
// exec.waitFor();
// }
//
// }
//
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
//
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
//
// protected String test;
// protected String result;
//
// protected SimpleUnit() {
// }
//
// public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// super(name, precondition, config, audit);
// this.test = test;
// this.result = result;
// }
//
// protected String getAudit() {
// String auditString = "out=$(" + super.getAudit() + ");\n";
// auditString += "test=\"" + getTest() + "\";\n";
//
// if (getResult().equals("fail"))
// auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// else
// auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// auditString += "\t" + getLabel() + "=0;\n";
// auditString += "else\n";
// auditString += "\t" + getLabel() + "=1;\n";
// auditString += "fi ;\n";
// return auditString;
// }
//
// protected String getTest() {
// return this.test;
// }
//
// protected String getResult() {
// return this.result;
// }
//
// }
// Path: src/core/model/NetworkModel.java
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit;
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
public void configServerBlock(String server, OutputStream out, InputStream in) {
String line = getAction("config", server);
//System.out.println(line);
ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
data.getServerPort(server), line, out);
exec.manageBlock();
}
private String getAction(String action, String server) {
System.out.println("=======================" + this.getLabel() + ":" + server + "==========================");
String line = this.getHeader(server, action) + "\n";
Vector<IProfile> serverRules = this.rules.get(server);
String configcmd = "";
if (data.getServerUpdate(server).equals("true")) {
configcmd = "sudo apt-get --assume-yes upgrade;";
} else {
configcmd = "echo \"$out\";";
}
serverRules.insertElementAt(new SimpleUnit("update", "proceed", configcmd,
"sudo apt-get update > /dev/null; sudo apt-get --assume-no upgrade | grep \"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\";",
"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "pass"), 0);
for (int i = 0; i < serverRules.size(); i++) { | IUnit unit = (IUnit) serverRules.elementAt(i); |
richardtynan/thornsec | src/core/profile/AProfile.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
| import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import core.iface.INetworkData;
import core.iface.IProfile; | package core.profile;
public abstract class AProfile implements IProfile {
protected String name;
protected AProfile(String name) {
this.name = name;
}
public String getLabel() {
return name;
}
public boolean isSingleton() {
return false;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
// Path: src/core/profile/AProfile.java
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import core.iface.INetworkData;
import core.iface.IProfile;
package core.profile;
public abstract class AProfile implements IProfile {
protected String name;
protected AProfile(String name) {
this.name = name;
}
public String getLabel() {
return name;
}
public boolean isSingleton() {
return false;
}
| public static String getProperty(String prop, String prof, String server, INetworkData data) { |
richardtynan/thornsec | src/core/unit/ASingleUnit.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit; | configString += "\t" + "echo 'fail " + getLabel() + " CONFIGURING'\n";
configString += "\t" + getConfig() + "\n";
configString += "\t" + "echo 'fail " + getLabel() + " RETESTING'\n";
configString += this.genAudit();
configString += "else\n";
configString += "\t" + getLabel() + "=0;\n";
configString += "\t" + "echo 'fail " + getLabel() + " PRECONDITION FAILED " + getPrecondition() + "'\n";
configString += "fi ;\n";
configString += "else\n";
configString += "\techo pass " + getLabel() + "\n";
configString += "\t" + "((pass++))\n";
configString += "fi ;\n";
return configString;
}
public String genDryRun() {
String dryrunString = this.getAudit();
dryrunString += "if [ \"$" + getLabel() + "\" != \"1\" ] ; then\n";
dryrunString += "\t" + "echo 'fail " + getLabel() + " DRYRUN'\n";
dryrunString += "\t" + "echo '" + getConfig() + "';\n";
dryrunString += this.getDryRun();
dryrunString += "\t" + "((fail++))\n";
dryrunString += "\t" + "fail_string=\"$fail_string\n" + getLabel() + "\"\n";
dryrunString += "else\n";
dryrunString += "\techo pass " + getLabel() + "\n";
dryrunString += "\t" + "((pass++))\n";
dryrunString += "fi ;\n";
return dryrunString;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
// Path: src/core/unit/ASingleUnit.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
configString += "\t" + "echo 'fail " + getLabel() + " CONFIGURING'\n";
configString += "\t" + getConfig() + "\n";
configString += "\t" + "echo 'fail " + getLabel() + " RETESTING'\n";
configString += this.genAudit();
configString += "else\n";
configString += "\t" + getLabel() + "=0;\n";
configString += "\t" + "echo 'fail " + getLabel() + " PRECONDITION FAILED " + getPrecondition() + "'\n";
configString += "fi ;\n";
configString += "else\n";
configString += "\techo pass " + getLabel() + "\n";
configString += "\t" + "((pass++))\n";
configString += "fi ;\n";
return configString;
}
public String genDryRun() {
String dryrunString = this.getAudit();
dryrunString += "if [ \"$" + getLabel() + "\" != \"1\" ] ; then\n";
dryrunString += "\t" + "echo 'fail " + getLabel() + " DRYRUN'\n";
dryrunString += "\t" + "echo '" + getConfig() + "';\n";
dryrunString += this.getDryRun();
dryrunString += "\t" + "((fail++))\n";
dryrunString += "\t" + "fail_string=\"$fail_string\n" + getLabel() + "\"\n";
dryrunString += "else\n";
dryrunString += "\techo pass " + getLabel() + "\n";
dryrunString += "\t" + "((pass++))\n";
dryrunString += "fi ;\n";
return dryrunString;
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
richardtynan/thornsec | src/core/unit/ASingleUnit.java | // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
| import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit; | configString += "\t" + "echo 'fail " + getLabel() + " CONFIGURING'\n";
configString += "\t" + getConfig() + "\n";
configString += "\t" + "echo 'fail " + getLabel() + " RETESTING'\n";
configString += this.genAudit();
configString += "else\n";
configString += "\t" + getLabel() + "=0;\n";
configString += "\t" + "echo 'fail " + getLabel() + " PRECONDITION FAILED " + getPrecondition() + "'\n";
configString += "fi ;\n";
configString += "else\n";
configString += "\techo pass " + getLabel() + "\n";
configString += "\t" + "((pass++))\n";
configString += "fi ;\n";
return configString;
}
public String genDryRun() {
String dryrunString = this.getAudit();
dryrunString += "if [ \"$" + getLabel() + "\" != \"1\" ] ; then\n";
dryrunString += "\t" + "echo 'fail " + getLabel() + " DRYRUN'\n";
dryrunString += "\t" + "echo '" + getConfig() + "';\n";
dryrunString += this.getDryRun();
dryrunString += "\t" + "((fail++))\n";
dryrunString += "\t" + "fail_string=\"$fail_string\n" + getLabel() + "\"\n";
dryrunString += "else\n";
dryrunString += "\techo pass " + getLabel() + "\n";
dryrunString += "\t" + "((pass++))\n";
dryrunString += "fi ;\n";
return dryrunString;
}
| // Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
//
// public String[] getServerLabels();
//
// public String[] getDeviceLabels();
//
// public String[] getDeviceMacs();
//
// public String[] getServerProfiles(String server);
//
// public String getServerData(String server, String label);
//
// public String getServerUser(String server);
//
// public String getServerIP(String server);
//
// public String getServerPort(String server);
//
// public String getServerUpdate(String server);
// }
//
// Path: src/core/iface/IProfile.java
// public interface IProfile {
//
// public String getLabel();
//
// public boolean isSingleton();
//
// public Vector<IProfile> getUnits(String server, INetworkData data);
//
// }
//
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
//
// public String genAudit();
//
// public String genConfig();
//
// public String genDryRun();
//
// }
// Path: src/core/unit/ASingleUnit.java
import java.util.Vector;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
configString += "\t" + "echo 'fail " + getLabel() + " CONFIGURING'\n";
configString += "\t" + getConfig() + "\n";
configString += "\t" + "echo 'fail " + getLabel() + " RETESTING'\n";
configString += this.genAudit();
configString += "else\n";
configString += "\t" + getLabel() + "=0;\n";
configString += "\t" + "echo 'fail " + getLabel() + " PRECONDITION FAILED " + getPrecondition() + "'\n";
configString += "fi ;\n";
configString += "else\n";
configString += "\techo pass " + getLabel() + "\n";
configString += "\t" + "((pass++))\n";
configString += "fi ;\n";
return configString;
}
public String genDryRun() {
String dryrunString = this.getAudit();
dryrunString += "if [ \"$" + getLabel() + "\" != \"1\" ] ; then\n";
dryrunString += "\t" + "echo 'fail " + getLabel() + " DRYRUN'\n";
dryrunString += "\t" + "echo '" + getConfig() + "';\n";
dryrunString += this.getDryRun();
dryrunString += "\t" + "((fail++))\n";
dryrunString += "\t" + "fail_string=\"$fail_string\n" + getLabel() + "\"\n";
dryrunString += "else\n";
dryrunString += "\techo pass " + getLabel() + "\n";
dryrunString += "\t" + "((pass++))\n";
dryrunString += "fi ;\n";
return dryrunString;
}
| public Vector<IProfile> getUnits(String server, INetworkData data) { |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/TransitRailTab.java | // Path: src/main/java/tk/cth451/transitrailmod/init/ModBlocks.java
// public class ModBlocks {
// public static Block closed_platform_top;
// public static Block closed_platform_door_block;
// public static Block closed_platform_panel_block;
// public static Block platform_gate_block;
// public static Block platform_panel_block;
// public static Block logo_block;
// public static Block hung_arrow_sign;
// public static Block platform_arrow_sign;
// public static Block fluorescent_lamp;
// public static Block wire_panel;
// public static Block wire_panel_corner;
// public static Block platform_sign;
// public static Block turnstile_block;
// public static Block ticket_machine;
// public static Block glass_fence;
// public static Block noise_barrier;
// public static Block noise_barrier_with_lamp;
// public static Block slim_passenger_detector;
//
// public static void init() {
// closed_platform_top = new ClosedPlatformTop(Material.IRON);
// closed_platform_door_block = new ClosedPlatformDoorBlock(Material.GLASS);
// closed_platform_panel_block = new ClosedPlatformPanelBlock(Material.GLASS);
// platform_gate_block = new PlatformGateBlock(Material.GLASS);
// platform_panel_block = new PlatformPanelBlock(Material.IRON);
// logo_block = new LogoBlock(Material.IRON);
// hung_arrow_sign = new HungArrowSign(Material.IRON);
// platform_arrow_sign = new PlatformArrowSign(Material.IRON);
// fluorescent_lamp = new FluorescentLamp(Material.GLASS);
// wire_panel = new WirePanel(Material.IRON);
// wire_panel_corner = new WirePanelCorner(Material.IRON);
// //platform_sign = new PlatformSign(Material.IRON);
// turnstile_block = new TurnstileBlock(Material.IRON);
// ticket_machine = new TicketMachine(Material.IRON);
// glass_fence = new GlassFenceBlock();
// noise_barrier = new NoiseBarrierBlock(false);
// noise_barrier_with_lamp = new NoiseBarrierBlock(true);
// slim_passenger_detector = new SlimPassengerDetector(Material.IRON);
// }
//
// public static void register() {
// GameRegistry.registerBlock(closed_platform_top, closed_platform_top.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(closed_platform_door_block, closed_platform_door_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(closed_platform_panel_block, closed_platform_panel_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(platform_gate_block, platform_gate_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(platform_panel_block, platform_panel_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(logo_block, logo_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(hung_arrow_sign, hung_arrow_sign.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(platform_arrow_sign, platform_arrow_sign.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(fluorescent_lamp, fluorescent_lamp.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(wire_panel, wire_panel.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(wire_panel_corner, wire_panel_corner.getUnlocalizedName().substring(5));
// //GameRegistry.registerBlock(platform_sign, platform_sign.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(turnstile_block, turnstile_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(ticket_machine, ticket_machine.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(glass_fence, glass_fence.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(noise_barrier, noise_barrier.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(noise_barrier_with_lamp, noise_barrier_with_lamp.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(slim_passenger_detector, slim_passenger_detector.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(closed_platform_top);
// registerRender(closed_platform_door_block);
// registerRender(closed_platform_panel_block);
// registerRender(platform_gate_block);
// registerRender(platform_panel_block);
// registerRender(logo_block);
// registerRender(hung_arrow_sign);
// registerRender(platform_arrow_sign);
// registerRender(fluorescent_lamp);
// registerRender(wire_panel);
// registerRender(wire_panel_corner);
// //registerRender(platform_sign);
// registerRender(turnstile_block);
// registerRender(ticket_machine);
// registerRender(glass_fence);
// registerRender(noise_barrier);
// registerRender(noise_barrier_with_lamp);
// registerRender(slim_passenger_detector);
// }
//
// public static void registerRender(Block block){
// Item item = Item.getItemFromBlock(block);
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
| import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import tk.cth451.transitrailmod.init.ModBlocks; | package tk.cth451.transitrailmod;
public class TransitRailTab extends CreativeTabs{
public TransitRailTab(String label) {
super(label);
// TODO Auto-generated constructor stub
}
@Override
public Item getTabIconItem() {
// TODO Auto-generated method stub | // Path: src/main/java/tk/cth451/transitrailmod/init/ModBlocks.java
// public class ModBlocks {
// public static Block closed_platform_top;
// public static Block closed_platform_door_block;
// public static Block closed_platform_panel_block;
// public static Block platform_gate_block;
// public static Block platform_panel_block;
// public static Block logo_block;
// public static Block hung_arrow_sign;
// public static Block platform_arrow_sign;
// public static Block fluorescent_lamp;
// public static Block wire_panel;
// public static Block wire_panel_corner;
// public static Block platform_sign;
// public static Block turnstile_block;
// public static Block ticket_machine;
// public static Block glass_fence;
// public static Block noise_barrier;
// public static Block noise_barrier_with_lamp;
// public static Block slim_passenger_detector;
//
// public static void init() {
// closed_platform_top = new ClosedPlatformTop(Material.IRON);
// closed_platform_door_block = new ClosedPlatformDoorBlock(Material.GLASS);
// closed_platform_panel_block = new ClosedPlatformPanelBlock(Material.GLASS);
// platform_gate_block = new PlatformGateBlock(Material.GLASS);
// platform_panel_block = new PlatformPanelBlock(Material.IRON);
// logo_block = new LogoBlock(Material.IRON);
// hung_arrow_sign = new HungArrowSign(Material.IRON);
// platform_arrow_sign = new PlatformArrowSign(Material.IRON);
// fluorescent_lamp = new FluorescentLamp(Material.GLASS);
// wire_panel = new WirePanel(Material.IRON);
// wire_panel_corner = new WirePanelCorner(Material.IRON);
// //platform_sign = new PlatformSign(Material.IRON);
// turnstile_block = new TurnstileBlock(Material.IRON);
// ticket_machine = new TicketMachine(Material.IRON);
// glass_fence = new GlassFenceBlock();
// noise_barrier = new NoiseBarrierBlock(false);
// noise_barrier_with_lamp = new NoiseBarrierBlock(true);
// slim_passenger_detector = new SlimPassengerDetector(Material.IRON);
// }
//
// public static void register() {
// GameRegistry.registerBlock(closed_platform_top, closed_platform_top.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(closed_platform_door_block, closed_platform_door_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(closed_platform_panel_block, closed_platform_panel_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(platform_gate_block, platform_gate_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(platform_panel_block, platform_panel_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(logo_block, logo_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(hung_arrow_sign, hung_arrow_sign.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(platform_arrow_sign, platform_arrow_sign.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(fluorescent_lamp, fluorescent_lamp.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(wire_panel, wire_panel.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(wire_panel_corner, wire_panel_corner.getUnlocalizedName().substring(5));
// //GameRegistry.registerBlock(platform_sign, platform_sign.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(turnstile_block, turnstile_block.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(ticket_machine, ticket_machine.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(glass_fence, glass_fence.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(noise_barrier, noise_barrier.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(noise_barrier_with_lamp, noise_barrier_with_lamp.getUnlocalizedName().substring(5));
// GameRegistry.registerBlock(slim_passenger_detector, slim_passenger_detector.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(closed_platform_top);
// registerRender(closed_platform_door_block);
// registerRender(closed_platform_panel_block);
// registerRender(platform_gate_block);
// registerRender(platform_panel_block);
// registerRender(logo_block);
// registerRender(hung_arrow_sign);
// registerRender(platform_arrow_sign);
// registerRender(fluorescent_lamp);
// registerRender(wire_panel);
// registerRender(wire_panel_corner);
// //registerRender(platform_sign);
// registerRender(turnstile_block);
// registerRender(ticket_machine);
// registerRender(glass_fence);
// registerRender(noise_barrier);
// registerRender(noise_barrier_with_lamp);
// registerRender(slim_passenger_detector);
// }
//
// public static void registerRender(Block block){
// Item item = Item.getItemFromBlock(block);
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/TransitRailTab.java
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import tk.cth451.transitrailmod.init.ModBlocks;
package tk.cth451.transitrailmod;
public class TransitRailTab extends CreativeTabs{
public TransitRailTab(String label) {
super(label);
// TODO Auto-generated constructor stub
}
@Override
public Item getTabIconItem() {
// TODO Auto-generated method stub | return Item.getItemFromBlock(ModBlocks.logo_block); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/LogoBlock.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
| import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import tk.cth451.transitrailmod.TransitRailMod; | package tk.cth451.transitrailmod.blocks;
public class LogoBlock extends Block {
public LogoBlock(Material materialIn) {
super(materialIn);
setHardness(1.5F);
setResistance(50);
setLightLevel(1F);
setUnlocalizedName("logo_block");
setHarvestLevel("pickaxe", 1); | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/LogoBlock.java
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import tk.cth451.transitrailmod.TransitRailMod;
package tk.cth451.transitrailmod.blocks;
public class LogoBlock extends Block {
public LogoBlock(Material materialIn) {
super(materialIn);
setHardness(1.5F);
setResistance(50);
setLightLevel(1F);
setUnlocalizedName("logo_block");
setHarvestLevel("pickaxe", 1); | setCreativeTab(TransitRailMod.tabTransitRail); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/ClosedPlatformPanelBlock.java | // Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ClosedPlatformBlock.java
// public abstract class ClosedPlatformBlock extends CustomDirectionBlock {
//
// public static final PropertyBool UPPER = PropertyBool.create("upper");
//
// public ClosedPlatformBlock(Material materialIn) {
// super(materialIn);
// }
//
// // Common Properties
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// protected boolean isUpper(IBlockAccess worldIn, BlockPos pos){
// return worldIn.getBlockState(pos.up()).getBlock() == ModBlocks.closed_platform_top;
// }
//
// // Interactions
// @Override
// public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
// ((World) world).notifyBlockOfStateChange(pos.down(), this);
// }
//
// protected void destroyParts(Boolean flagUpper, World worldIn, BlockPos thisPos){
// BlockPos pos2 = flagUpper ? thisPos.up() : thisPos.up(2);
// // pos2 = the top part
// worldIn.setBlockToAir(thisPos);
// // destroy self
// worldIn.setBlockToAir(pos2);
// // destroy top
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/init/ModItems.java
// public class ModItems {
// public static Item style_changer;
// public static Item closed_platform_door_item;
// public static Item closed_platform_panel_item;
// public static Item platform_gate_item;
// public static Item platform_panel_item;
// public static Item train_ticket;
//
// public static void init(){
// style_changer = new StyleChanger();
// closed_platform_door_item = new ClosedPlatformDoorItem();
// closed_platform_panel_item = new ClosedPlatformPanelItem();
// platform_gate_item = new PlatformGateItem();
// platform_panel_item = new PlatformPanelItem();
// train_ticket = new TrainTicket();
// }
//
// public static void register(){
// GameRegistry.registerItem(style_changer, style_changer.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_door_item, closed_platform_door_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_panel_item, closed_platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_gate_item, platform_gate_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_panel_item, platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(train_ticket, train_ticket.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(style_changer);
// registerRender(closed_platform_door_item);
// registerRender(closed_platform_panel_item);
// registerRender(platform_gate_item);
// registerRender(platform_panel_item);
// registerRender(train_ticket);
// }
//
// public static void registerRender(Item item){
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
| import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.blocks.prototype.ClosedPlatformBlock;
import tk.cth451.transitrailmod.init.ModItems; | @Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING, UPPER});
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
return state.withProperty(UPPER, isUpper(worldIn, pos));
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
// Interactions
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos)
{
return this.getItem();
}
private Item getItem() { | // Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ClosedPlatformBlock.java
// public abstract class ClosedPlatformBlock extends CustomDirectionBlock {
//
// public static final PropertyBool UPPER = PropertyBool.create("upper");
//
// public ClosedPlatformBlock(Material materialIn) {
// super(materialIn);
// }
//
// // Common Properties
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// protected boolean isUpper(IBlockAccess worldIn, BlockPos pos){
// return worldIn.getBlockState(pos.up()).getBlock() == ModBlocks.closed_platform_top;
// }
//
// // Interactions
// @Override
// public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
// ((World) world).notifyBlockOfStateChange(pos.down(), this);
// }
//
// protected void destroyParts(Boolean flagUpper, World worldIn, BlockPos thisPos){
// BlockPos pos2 = flagUpper ? thisPos.up() : thisPos.up(2);
// // pos2 = the top part
// worldIn.setBlockToAir(thisPos);
// // destroy self
// worldIn.setBlockToAir(pos2);
// // destroy top
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/init/ModItems.java
// public class ModItems {
// public static Item style_changer;
// public static Item closed_platform_door_item;
// public static Item closed_platform_panel_item;
// public static Item platform_gate_item;
// public static Item platform_panel_item;
// public static Item train_ticket;
//
// public static void init(){
// style_changer = new StyleChanger();
// closed_platform_door_item = new ClosedPlatformDoorItem();
// closed_platform_panel_item = new ClosedPlatformPanelItem();
// platform_gate_item = new PlatformGateItem();
// platform_panel_item = new PlatformPanelItem();
// train_ticket = new TrainTicket();
// }
//
// public static void register(){
// GameRegistry.registerItem(style_changer, style_changer.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_door_item, closed_platform_door_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_panel_item, closed_platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_gate_item, platform_gate_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_panel_item, platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(train_ticket, train_ticket.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(style_changer);
// registerRender(closed_platform_door_item);
// registerRender(closed_platform_panel_item);
// registerRender(platform_gate_item);
// registerRender(platform_panel_item);
// registerRender(train_ticket);
// }
//
// public static void registerRender(Item item){
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/ClosedPlatformPanelBlock.java
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.blocks.prototype.ClosedPlatformBlock;
import tk.cth451.transitrailmod.init.ModItems;
@Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING, UPPER});
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
return state.withProperty(UPPER, isUpper(worldIn, pos));
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
// Interactions
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos)
{
return this.getItem();
}
private Item getItem() { | return ModItems.closed_platform_panel_item; |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/PlatformPanelBlock.java | // Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/PlatformBlock.java
// public abstract class PlatformBlock extends CustomDirectionBlock {
//
// public static final PropertyBool UPPER = PropertyBool.create("upper");
//
// public PlatformBlock(Material materialIn) {
// super(materialIn);
// }
//
// // Common Properties
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isFullBlock(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// public boolean isUpper(IBlockAccess worldIn, BlockPos pos){
// return worldIn.getBlockState(pos.down()).getBlock().equals(this);
// }
//
// // Block States
// @Override
// public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
// return state.withProperty(UPPER, isUpper(worldIn, pos));
// }
//
// // Interactions
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// @Override
// public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
// BlockPos posToCheck = this.isUpper(worldIn, pos) ? pos.down() : pos.up();
// if (worldIn.getBlockState(posToCheck).getBlock() != this) {
// worldIn.setBlockToAir(pos);
// worldIn.notifyBlockOfStateChange(pos.up(), this);
// }
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/init/ModItems.java
// public class ModItems {
// public static Item style_changer;
// public static Item closed_platform_door_item;
// public static Item closed_platform_panel_item;
// public static Item platform_gate_item;
// public static Item platform_panel_item;
// public static Item train_ticket;
//
// public static void init(){
// style_changer = new StyleChanger();
// closed_platform_door_item = new ClosedPlatformDoorItem();
// closed_platform_panel_item = new ClosedPlatformPanelItem();
// platform_gate_item = new PlatformGateItem();
// platform_panel_item = new PlatformPanelItem();
// train_ticket = new TrainTicket();
// }
//
// public static void register(){
// GameRegistry.registerItem(style_changer, style_changer.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_door_item, closed_platform_door_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_panel_item, closed_platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_gate_item, platform_gate_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_panel_item, platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(train_ticket, train_ticket.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(style_changer);
// registerRender(closed_platform_door_item);
// registerRender(closed_platform_panel_item);
// registerRender(platform_gate_item);
// registerRender(platform_panel_item);
// registerRender(train_ticket);
// }
//
// public static void registerRender(Item item){
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
| import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.blocks.prototype.PlatformBlock;
import tk.cth451.transitrailmod.init.ModItems; | } else { // if (facing == EnumFacing.WEST) {
return new AxisAlignedBB(0.125F, 0.0F, 0.0F, 0.25F, 1.0F, 1.0F);
}
}
}
// Blockstates
@Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING, UPPER});
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
// Redstone and interactions
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos)
{
return this.getItem();
}
private Item getItem() { | // Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/PlatformBlock.java
// public abstract class PlatformBlock extends CustomDirectionBlock {
//
// public static final PropertyBool UPPER = PropertyBool.create("upper");
//
// public PlatformBlock(Material materialIn) {
// super(materialIn);
// }
//
// // Common Properties
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isFullBlock(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// public boolean isUpper(IBlockAccess worldIn, BlockPos pos){
// return worldIn.getBlockState(pos.down()).getBlock().equals(this);
// }
//
// // Block States
// @Override
// public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
// return state.withProperty(UPPER, isUpper(worldIn, pos));
// }
//
// // Interactions
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// @Override
// public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
// BlockPos posToCheck = this.isUpper(worldIn, pos) ? pos.down() : pos.up();
// if (worldIn.getBlockState(posToCheck).getBlock() != this) {
// worldIn.setBlockToAir(pos);
// worldIn.notifyBlockOfStateChange(pos.up(), this);
// }
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/init/ModItems.java
// public class ModItems {
// public static Item style_changer;
// public static Item closed_platform_door_item;
// public static Item closed_platform_panel_item;
// public static Item platform_gate_item;
// public static Item platform_panel_item;
// public static Item train_ticket;
//
// public static void init(){
// style_changer = new StyleChanger();
// closed_platform_door_item = new ClosedPlatformDoorItem();
// closed_platform_panel_item = new ClosedPlatformPanelItem();
// platform_gate_item = new PlatformGateItem();
// platform_panel_item = new PlatformPanelItem();
// train_ticket = new TrainTicket();
// }
//
// public static void register(){
// GameRegistry.registerItem(style_changer, style_changer.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_door_item, closed_platform_door_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_panel_item, closed_platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_gate_item, platform_gate_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_panel_item, platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(train_ticket, train_ticket.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(style_changer);
// registerRender(closed_platform_door_item);
// registerRender(closed_platform_panel_item);
// registerRender(platform_gate_item);
// registerRender(platform_panel_item);
// registerRender(train_ticket);
// }
//
// public static void registerRender(Item item){
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/PlatformPanelBlock.java
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.blocks.prototype.PlatformBlock;
import tk.cth451.transitrailmod.init.ModItems;
} else { // if (facing == EnumFacing.WEST) {
return new AxisAlignedBB(0.125F, 0.0F, 0.0F, 0.25F, 1.0F, 1.0F);
}
}
}
// Blockstates
@Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING, UPPER});
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
// Redstone and interactions
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos)
{
return this.getItem();
}
private Item getItem() { | return ModItems.platform_panel_item; |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/init/ModTileEntities.java | // Path: src/main/java/tk/cth451/transitrailmod/tileentities/PlatformSignEntity.java
// public class PlatformSignEntity extends TileEntity{
// private String dataContent;
//
// public PlatformSignEntity(String stringIn) {
// dataContent = stringIn;
// }
//
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// compound = super.writeToNBT(compound);
// compound.setString("content", dataContent);
// return compound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound compound) {
// super.readFromNBT(compound);
// this.dataContent = compound.getString("content");
// }
// }
| import net.minecraftforge.fml.common.registry.GameRegistry;
import tk.cth451.transitrailmod.tileentities.PlatformSignEntity; | package tk.cth451.transitrailmod.init;
public class ModTileEntities {
public static void register() { | // Path: src/main/java/tk/cth451/transitrailmod/tileentities/PlatformSignEntity.java
// public class PlatformSignEntity extends TileEntity{
// private String dataContent;
//
// public PlatformSignEntity(String stringIn) {
// dataContent = stringIn;
// }
//
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// compound = super.writeToNBT(compound);
// compound.setString("content", dataContent);
// return compound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound compound) {
// super.readFromNBT(compound);
// this.dataContent = compound.getString("content");
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/init/ModTileEntities.java
import net.minecraftforge.fml.common.registry.GameRegistry;
import tk.cth451.transitrailmod.tileentities.PlatformSignEntity;
package tk.cth451.transitrailmod.init;
public class ModTileEntities {
public static void register() { | GameRegistry.registerTileEntity(PlatformSignEntity.class, "platform_sign_entity"); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/PlatformArrowSign.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ArrowSign.java
// public abstract class ArrowSign extends CustomDirectionBlock {
//
// public static final PropertyEnum ARROW = PropertyEnum.create("arrow", EnumArrow.class);
//
// public ArrowSign(Material materialIn) {
// super(Material.IRON);
// this.setLightLevel(1.0F);
// this.setDefaultState(getDefaultState()
// .withProperty(ARROW, EnumArrow.ARROW_UP)
// .withProperty(FACING, EnumFacing.NORTH));
// }
//
// // Block state
// @Override
// protected BlockStateContainer createBlockState() {
// return new BlockStateContainer(this, new IProperty[] {ARROW, FACING});
// }
//
// // meta 1122
// // 11: ARROW
// // 22: FACING
// @Override
// public IBlockState getStateFromMeta(int meta) {
// EnumFacing pFacing = EnumFacing.getHorizontal(meta % 4);
// EnumArrow pArrow = EnumArrow.fromMeta(meta / 4);
// return this.getDefaultState().withProperty(ARROW, pArrow).withProperty(FACING, pFacing);
// }
//
// @Override
// public int getMetaFromState(IBlockState state) {
// int mFacing = ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
// int mArrow = ((EnumArrow) state.getValue(ARROW)).toMeta();
// return mArrow * 4 + mFacing;
// }
//
// // Properties
//
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// // Interactions
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
| import net.minecraft.block.material.Material;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.ArrowSign; | package tk.cth451.transitrailmod.blocks;
public class PlatformArrowSign extends ArrowSign {
public PlatformArrowSign(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("platform_arrow_sign"); | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ArrowSign.java
// public abstract class ArrowSign extends CustomDirectionBlock {
//
// public static final PropertyEnum ARROW = PropertyEnum.create("arrow", EnumArrow.class);
//
// public ArrowSign(Material materialIn) {
// super(Material.IRON);
// this.setLightLevel(1.0F);
// this.setDefaultState(getDefaultState()
// .withProperty(ARROW, EnumArrow.ARROW_UP)
// .withProperty(FACING, EnumFacing.NORTH));
// }
//
// // Block state
// @Override
// protected BlockStateContainer createBlockState() {
// return new BlockStateContainer(this, new IProperty[] {ARROW, FACING});
// }
//
// // meta 1122
// // 11: ARROW
// // 22: FACING
// @Override
// public IBlockState getStateFromMeta(int meta) {
// EnumFacing pFacing = EnumFacing.getHorizontal(meta % 4);
// EnumArrow pArrow = EnumArrow.fromMeta(meta / 4);
// return this.getDefaultState().withProperty(ARROW, pArrow).withProperty(FACING, pFacing);
// }
//
// @Override
// public int getMetaFromState(IBlockState state) {
// int mFacing = ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
// int mArrow = ((EnumArrow) state.getValue(ARROW)).toMeta();
// return mArrow * 4 + mFacing;
// }
//
// // Properties
//
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// // Interactions
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/PlatformArrowSign.java
import net.minecraft.block.material.Material;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.ArrowSign;
package tk.cth451.transitrailmod.blocks;
public class PlatformArrowSign extends ArrowSign {
public PlatformArrowSign(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("platform_arrow_sign"); | this.setCreativeTab(TransitRailMod.tabTransitRail); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/PlatformSign.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/tileentities/PlatformSignEntity.java
// public class PlatformSignEntity extends TileEntity{
// private String dataContent;
//
// public PlatformSignEntity(String stringIn) {
// dataContent = stringIn;
// }
//
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// compound = super.writeToNBT(compound);
// compound.setString("content", dataContent);
// return compound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound compound) {
// super.readFromNBT(compound);
// this.dataContent = compound.getString("content");
// }
// }
| import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.tileentities.PlatformSignEntity; | package tk.cth451.transitrailmod.blocks;
public class PlatformSign extends BlockContainer {
public PlatformSign(Material materialIn) {
super(materialIn);
setHardness(1.5F);
setResistance(50);
setLightLevel(0.7F);
setHarvestLevel("pickaxe", 1);
setUnlocalizedName("platform_sign"); | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/tileentities/PlatformSignEntity.java
// public class PlatformSignEntity extends TileEntity{
// private String dataContent;
//
// public PlatformSignEntity(String stringIn) {
// dataContent = stringIn;
// }
//
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// compound = super.writeToNBT(compound);
// compound.setString("content", dataContent);
// return compound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound compound) {
// super.readFromNBT(compound);
// this.dataContent = compound.getString("content");
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/PlatformSign.java
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.tileentities.PlatformSignEntity;
package tk.cth451.transitrailmod.blocks;
public class PlatformSign extends BlockContainer {
public PlatformSign(Material materialIn) {
super(materialIn);
setHardness(1.5F);
setResistance(50);
setLightLevel(0.7F);
setHarvestLevel("pickaxe", 1);
setUnlocalizedName("platform_sign"); | setCreativeTab(TransitRailMod.tabTransitRail); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/PlatformSign.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/tileentities/PlatformSignEntity.java
// public class PlatformSignEntity extends TileEntity{
// private String dataContent;
//
// public PlatformSignEntity(String stringIn) {
// dataContent = stringIn;
// }
//
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// compound = super.writeToNBT(compound);
// compound.setString("content", dataContent);
// return compound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound compound) {
// super.readFromNBT(compound);
// this.dataContent = compound.getString("content");
// }
// }
| import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.tileentities.PlatformSignEntity; | package tk.cth451.transitrailmod.blocks;
public class PlatformSign extends BlockContainer {
public PlatformSign(Material materialIn) {
super(materialIn);
setHardness(1.5F);
setResistance(50);
setLightLevel(0.7F);
setHarvestLevel("pickaxe", 1);
setUnlocalizedName("platform_sign");
setCreativeTab(TransitRailMod.tabTransitRail);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) { | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/tileentities/PlatformSignEntity.java
// public class PlatformSignEntity extends TileEntity{
// private String dataContent;
//
// public PlatformSignEntity(String stringIn) {
// dataContent = stringIn;
// }
//
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// compound = super.writeToNBT(compound);
// compound.setString("content", dataContent);
// return compound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound compound) {
// super.readFromNBT(compound);
// this.dataContent = compound.getString("content");
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/PlatformSign.java
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.tileentities.PlatformSignEntity;
package tk.cth451.transitrailmod.blocks;
public class PlatformSign extends BlockContainer {
public PlatformSign(Material materialIn) {
super(materialIn);
setHardness(1.5F);
setResistance(50);
setLightLevel(0.7F);
setHarvestLevel("pickaxe", 1);
setUnlocalizedName("platform_sign");
setCreativeTab(TransitRailMod.tabTransitRail);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) { | return new PlatformSignEntity(""); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/ClosedPlatformDoorBlock.java | // Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ClosedPlatformBlock.java
// public abstract class ClosedPlatformBlock extends CustomDirectionBlock {
//
// public static final PropertyBool UPPER = PropertyBool.create("upper");
//
// public ClosedPlatformBlock(Material materialIn) {
// super(materialIn);
// }
//
// // Common Properties
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// protected boolean isUpper(IBlockAccess worldIn, BlockPos pos){
// return worldIn.getBlockState(pos.up()).getBlock() == ModBlocks.closed_platform_top;
// }
//
// // Interactions
// @Override
// public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
// ((World) world).notifyBlockOfStateChange(pos.down(), this);
// }
//
// protected void destroyParts(Boolean flagUpper, World worldIn, BlockPos thisPos){
// BlockPos pos2 = flagUpper ? thisPos.up() : thisPos.up(2);
// // pos2 = the top part
// worldIn.setBlockToAir(thisPos);
// // destroy self
// worldIn.setBlockToAir(pos2);
// // destroy top
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/init/ModItems.java
// public class ModItems {
// public static Item style_changer;
// public static Item closed_platform_door_item;
// public static Item closed_platform_panel_item;
// public static Item platform_gate_item;
// public static Item platform_panel_item;
// public static Item train_ticket;
//
// public static void init(){
// style_changer = new StyleChanger();
// closed_platform_door_item = new ClosedPlatformDoorItem();
// closed_platform_panel_item = new ClosedPlatformPanelItem();
// platform_gate_item = new PlatformGateItem();
// platform_panel_item = new PlatformPanelItem();
// train_ticket = new TrainTicket();
// }
//
// public static void register(){
// GameRegistry.registerItem(style_changer, style_changer.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_door_item, closed_platform_door_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_panel_item, closed_platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_gate_item, platform_gate_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_panel_item, platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(train_ticket, train_ticket.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(style_changer);
// registerRender(closed_platform_door_item);
// registerRender(closed_platform_panel_item);
// registerRender(platform_gate_item);
// registerRender(platform_panel_item);
// registerRender(train_ticket);
// }
//
// public static void registerRender(Item item){
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
| import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.blocks.prototype.ClosedPlatformBlock;
import tk.cth451.transitrailmod.init.ModItems; | // 2: powered
// 11 : facing
@Override
public int getMetaFromState(IBlockState state) {
int mFacing = ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
int mPowered = (Boolean) state.getValue(POWERED) ? 1 : 0;
return mPowered *4 + mFacing;
}
// meta: 0211
// 2: powered
// 11 : facing
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing pFacing = EnumFacing.getHorizontal(meta % 4);
boolean pPowered = meta / 4 == 1;
return this.getDefaultState().withProperty(FACING, pFacing).withProperty(POWERED, pPowered);
}
public boolean isLeft(IBlockAccess worldIn, BlockPos pos, EnumFacing direc){
return worldIn.getBlockState(pos.offset(direc.rotateY())).getBlock().equals(this);
}
// Interactions
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos) {
return this.getItem();
}
private Item getItem() { | // Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ClosedPlatformBlock.java
// public abstract class ClosedPlatformBlock extends CustomDirectionBlock {
//
// public static final PropertyBool UPPER = PropertyBool.create("upper");
//
// public ClosedPlatformBlock(Material materialIn) {
// super(materialIn);
// }
//
// // Common Properties
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// public boolean isFullCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// protected boolean isUpper(IBlockAccess worldIn, BlockPos pos){
// return worldIn.getBlockState(pos.up()).getBlock() == ModBlocks.closed_platform_top;
// }
//
// // Interactions
// @Override
// public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
// ((World) world).notifyBlockOfStateChange(pos.down(), this);
// }
//
// protected void destroyParts(Boolean flagUpper, World worldIn, BlockPos thisPos){
// BlockPos pos2 = flagUpper ? thisPos.up() : thisPos.up(2);
// // pos2 = the top part
// worldIn.setBlockToAir(thisPos);
// // destroy self
// worldIn.setBlockToAir(pos2);
// // destroy top
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/init/ModItems.java
// public class ModItems {
// public static Item style_changer;
// public static Item closed_platform_door_item;
// public static Item closed_platform_panel_item;
// public static Item platform_gate_item;
// public static Item platform_panel_item;
// public static Item train_ticket;
//
// public static void init(){
// style_changer = new StyleChanger();
// closed_platform_door_item = new ClosedPlatformDoorItem();
// closed_platform_panel_item = new ClosedPlatformPanelItem();
// platform_gate_item = new PlatformGateItem();
// platform_panel_item = new PlatformPanelItem();
// train_ticket = new TrainTicket();
// }
//
// public static void register(){
// GameRegistry.registerItem(style_changer, style_changer.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_door_item, closed_platform_door_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(closed_platform_panel_item, closed_platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_gate_item, platform_gate_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(platform_panel_item, platform_panel_item.getUnlocalizedName().substring(5));
// GameRegistry.registerItem(train_ticket, train_ticket.getUnlocalizedName().substring(5));
// }
//
// public static void registerRenders(){
// registerRender(style_changer);
// registerRender(closed_platform_door_item);
// registerRender(closed_platform_panel_item);
// registerRender(platform_gate_item);
// registerRender(platform_panel_item);
// registerRender(train_ticket);
// }
//
// public static void registerRender(Item item){
// Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/ClosedPlatformDoorBlock.java
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.blocks.prototype.ClosedPlatformBlock;
import tk.cth451.transitrailmod.init.ModItems;
// 2: powered
// 11 : facing
@Override
public int getMetaFromState(IBlockState state) {
int mFacing = ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
int mPowered = (Boolean) state.getValue(POWERED) ? 1 : 0;
return mPowered *4 + mFacing;
}
// meta: 0211
// 2: powered
// 11 : facing
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing pFacing = EnumFacing.getHorizontal(meta % 4);
boolean pPowered = meta / 4 == 1;
return this.getDefaultState().withProperty(FACING, pFacing).withProperty(POWERED, pPowered);
}
public boolean isLeft(IBlockAccess worldIn, BlockPos pos, EnumFacing direc){
return worldIn.getBlockState(pos.offset(direc.rotateY())).getBlock().equals(this);
}
// Interactions
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, BlockPos pos) {
return this.getItem();
}
private Item getItem() { | return ModItems.closed_platform_door_item; |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/TicketMachine.java | // Path: src/main/java/tk/cth451/transitrailmod/EnumGuiTypes.java
// public enum EnumGuiTypes {
// TICKET_MACHINE;
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
| import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.EnumGuiTypes;
import tk.cth451.transitrailmod.TransitRailMod; | package tk.cth451.transitrailmod.blocks;
public class TicketMachine extends Block {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public TicketMachine(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("ticket_machine"); | // Path: src/main/java/tk/cth451/transitrailmod/EnumGuiTypes.java
// public enum EnumGuiTypes {
// TICKET_MACHINE;
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/TicketMachine.java
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.EnumGuiTypes;
import tk.cth451.transitrailmod.TransitRailMod;
package tk.cth451.transitrailmod.blocks;
public class TicketMachine extends Block {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public TicketMachine(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("ticket_machine"); | this.setCreativeTab(TransitRailMod.tabTransitRail); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/TicketMachine.java | // Path: src/main/java/tk/cth451/transitrailmod/EnumGuiTypes.java
// public enum EnumGuiTypes {
// TICKET_MACHINE;
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
| import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.EnumGuiTypes;
import tk.cth451.transitrailmod.TransitRailMod; | }
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
@Override
public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
return true;
}
// Interactions
@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// set facing to the direction player is facing
IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
return this.getFacingState(state, placer);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
playerIn.openGui(TransitRailMod.instance, | // Path: src/main/java/tk/cth451/transitrailmod/EnumGuiTypes.java
// public enum EnumGuiTypes {
// TICKET_MACHINE;
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/TicketMachine.java
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.EnumGuiTypes;
import tk.cth451.transitrailmod.TransitRailMod;
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
@Override
public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
return true;
}
// Interactions
@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// set facing to the direction player is facing
IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
return this.getFacingState(state, placer);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
playerIn.openGui(TransitRailMod.instance, | EnumGuiTypes.TICKET_MACHINE.ordinal(), |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/TurnstileBlock.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/CustomDirectionBlock.java
// public abstract class CustomDirectionBlock extends Block {
//
// public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
//
// public CustomDirectionBlock(Material materialIn) {
// super(materialIn);
// }
//
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// protected IBlockState getFacingState(IBlockState state, EntityLivingBase placer){
// EnumFacing thisFacing = placer.getHorizontalFacing();
// return state.withProperty(FACING, thisFacing);
// }
//
// @Override
// public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
// List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
// addCollisionBoxToList(pos, entityBox, collidingBoxes, state.getCollisionBoundingBox(worldIn, pos));
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/enums/EnumPassingDirection.java
// public enum EnumPassingDirection implements IStringSerializable {
// INSIDE,
// OUTSIDE;
//
// public int toMeta() {
// return this == INSIDE ? 0 : 1;
// }
//
// public static EnumPassingDirection fromMeta(int meta) {
// return meta == 0 ? INSIDE : OUTSIDE;
// }
//
// @Override
// public String getName() {
// return this == INSIDE ? "inside" : "outside";
// }
//
// @Override
// public String toString() {
// return this.getName();
// }
//
// public boolean isInside() {
// return this == INSIDE ? true : false;
// }
// }
| import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.CustomDirectionBlock;
import tk.cth451.transitrailmod.enums.EnumPassingDirection; | package tk.cth451.transitrailmod.blocks;
public class TurnstileBlock extends CustomDirectionBlock{
public static final PropertyBool ACTIVE = PropertyBool.create("active");
// whether the turnstile has processed the ticket and open the gate | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/CustomDirectionBlock.java
// public abstract class CustomDirectionBlock extends Block {
//
// public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
//
// public CustomDirectionBlock(Material materialIn) {
// super(materialIn);
// }
//
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// protected IBlockState getFacingState(IBlockState state, EntityLivingBase placer){
// EnumFacing thisFacing = placer.getHorizontalFacing();
// return state.withProperty(FACING, thisFacing);
// }
//
// @Override
// public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
// List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
// addCollisionBoxToList(pos, entityBox, collidingBoxes, state.getCollisionBoundingBox(worldIn, pos));
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/enums/EnumPassingDirection.java
// public enum EnumPassingDirection implements IStringSerializable {
// INSIDE,
// OUTSIDE;
//
// public int toMeta() {
// return this == INSIDE ? 0 : 1;
// }
//
// public static EnumPassingDirection fromMeta(int meta) {
// return meta == 0 ? INSIDE : OUTSIDE;
// }
//
// @Override
// public String getName() {
// return this == INSIDE ? "inside" : "outside";
// }
//
// @Override
// public String toString() {
// return this.getName();
// }
//
// public boolean isInside() {
// return this == INSIDE ? true : false;
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/TurnstileBlock.java
import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.CustomDirectionBlock;
import tk.cth451.transitrailmod.enums.EnumPassingDirection;
package tk.cth451.transitrailmod.blocks;
public class TurnstileBlock extends CustomDirectionBlock{
public static final PropertyBool ACTIVE = PropertyBool.create("active");
// whether the turnstile has processed the ticket and open the gate | public static final PropertyEnum PASSING = PropertyEnum.create("passing", EnumPassingDirection.class); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/TurnstileBlock.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/CustomDirectionBlock.java
// public abstract class CustomDirectionBlock extends Block {
//
// public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
//
// public CustomDirectionBlock(Material materialIn) {
// super(materialIn);
// }
//
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// protected IBlockState getFacingState(IBlockState state, EntityLivingBase placer){
// EnumFacing thisFacing = placer.getHorizontalFacing();
// return state.withProperty(FACING, thisFacing);
// }
//
// @Override
// public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
// List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
// addCollisionBoxToList(pos, entityBox, collidingBoxes, state.getCollisionBoundingBox(worldIn, pos));
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/enums/EnumPassingDirection.java
// public enum EnumPassingDirection implements IStringSerializable {
// INSIDE,
// OUTSIDE;
//
// public int toMeta() {
// return this == INSIDE ? 0 : 1;
// }
//
// public static EnumPassingDirection fromMeta(int meta) {
// return meta == 0 ? INSIDE : OUTSIDE;
// }
//
// @Override
// public String getName() {
// return this == INSIDE ? "inside" : "outside";
// }
//
// @Override
// public String toString() {
// return this.getName();
// }
//
// public boolean isInside() {
// return this == INSIDE ? true : false;
// }
// }
| import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.CustomDirectionBlock;
import tk.cth451.transitrailmod.enums.EnumPassingDirection; | package tk.cth451.transitrailmod.blocks;
public class TurnstileBlock extends CustomDirectionBlock{
public static final PropertyBool ACTIVE = PropertyBool.create("active");
// whether the turnstile has processed the ticket and open the gate
public static final PropertyEnum PASSING = PropertyEnum.create("passing", EnumPassingDirection.class);
public TurnstileBlock(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("turnstile_block"); | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/CustomDirectionBlock.java
// public abstract class CustomDirectionBlock extends Block {
//
// public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
//
// public CustomDirectionBlock(Material materialIn) {
// super(materialIn);
// }
//
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// protected IBlockState getFacingState(IBlockState state, EntityLivingBase placer){
// EnumFacing thisFacing = placer.getHorizontalFacing();
// return state.withProperty(FACING, thisFacing);
// }
//
// @Override
// public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
// List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
// addCollisionBoxToList(pos, entityBox, collidingBoxes, state.getCollisionBoundingBox(worldIn, pos));
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/enums/EnumPassingDirection.java
// public enum EnumPassingDirection implements IStringSerializable {
// INSIDE,
// OUTSIDE;
//
// public int toMeta() {
// return this == INSIDE ? 0 : 1;
// }
//
// public static EnumPassingDirection fromMeta(int meta) {
// return meta == 0 ? INSIDE : OUTSIDE;
// }
//
// @Override
// public String getName() {
// return this == INSIDE ? "inside" : "outside";
// }
//
// @Override
// public String toString() {
// return this.getName();
// }
//
// public boolean isInside() {
// return this == INSIDE ? true : false;
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/TurnstileBlock.java
import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.CustomDirectionBlock;
import tk.cth451.transitrailmod.enums.EnumPassingDirection;
package tk.cth451.transitrailmod.blocks;
public class TurnstileBlock extends CustomDirectionBlock{
public static final PropertyBool ACTIVE = PropertyBool.create("active");
// whether the turnstile has processed the ticket and open the gate
public static final PropertyEnum PASSING = PropertyEnum.create("passing", EnumPassingDirection.class);
public TurnstileBlock(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("turnstile_block"); | this.setCreativeTab(TransitRailMod.tabTransitRail); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/HungArrowSign.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ArrowSign.java
// public abstract class ArrowSign extends CustomDirectionBlock {
//
// public static final PropertyEnum ARROW = PropertyEnum.create("arrow", EnumArrow.class);
//
// public ArrowSign(Material materialIn) {
// super(Material.IRON);
// this.setLightLevel(1.0F);
// this.setDefaultState(getDefaultState()
// .withProperty(ARROW, EnumArrow.ARROW_UP)
// .withProperty(FACING, EnumFacing.NORTH));
// }
//
// // Block state
// @Override
// protected BlockStateContainer createBlockState() {
// return new BlockStateContainer(this, new IProperty[] {ARROW, FACING});
// }
//
// // meta 1122
// // 11: ARROW
// // 22: FACING
// @Override
// public IBlockState getStateFromMeta(int meta) {
// EnumFacing pFacing = EnumFacing.getHorizontal(meta % 4);
// EnumArrow pArrow = EnumArrow.fromMeta(meta / 4);
// return this.getDefaultState().withProperty(ARROW, pArrow).withProperty(FACING, pFacing);
// }
//
// @Override
// public int getMetaFromState(IBlockState state) {
// int mFacing = ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
// int mArrow = ((EnumArrow) state.getValue(ARROW)).toMeta();
// return mArrow * 4 + mFacing;
// }
//
// // Properties
//
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// // Interactions
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
| import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.ArrowSign; | package tk.cth451.transitrailmod.blocks;
public class HungArrowSign extends ArrowSign {
public HungArrowSign(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("hung_arrow_sign"); | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
//
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/ArrowSign.java
// public abstract class ArrowSign extends CustomDirectionBlock {
//
// public static final PropertyEnum ARROW = PropertyEnum.create("arrow", EnumArrow.class);
//
// public ArrowSign(Material materialIn) {
// super(Material.IRON);
// this.setLightLevel(1.0F);
// this.setDefaultState(getDefaultState()
// .withProperty(ARROW, EnumArrow.ARROW_UP)
// .withProperty(FACING, EnumFacing.NORTH));
// }
//
// // Block state
// @Override
// protected BlockStateContainer createBlockState() {
// return new BlockStateContainer(this, new IProperty[] {ARROW, FACING});
// }
//
// // meta 1122
// // 11: ARROW
// // 22: FACING
// @Override
// public IBlockState getStateFromMeta(int meta) {
// EnumFacing pFacing = EnumFacing.getHorizontal(meta % 4);
// EnumArrow pArrow = EnumArrow.fromMeta(meta / 4);
// return this.getDefaultState().withProperty(ARROW, pArrow).withProperty(FACING, pFacing);
// }
//
// @Override
// public int getMetaFromState(IBlockState state) {
// int mFacing = ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
// int mArrow = ((EnumArrow) state.getValue(ARROW)).toMeta();
// return mArrow * 4 + mFacing;
// }
//
// // Properties
//
// @Override
// public boolean isTranslucent(IBlockState state) {
// return true;
// }
//
// @Override
// public boolean isOpaqueCube(IBlockState state) {
// return false;
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public BlockRenderLayer getBlockLayer() {
// return BlockRenderLayer.CUTOUT;
// }
//
// // Interactions
// @Override
// public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
// // set facing to the direction player is facing
// IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
// return this.getFacingState(state, placer);
// }
//
// @Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/HungArrowSign.java
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import tk.cth451.transitrailmod.TransitRailMod;
import tk.cth451.transitrailmod.blocks.prototype.ArrowSign;
package tk.cth451.transitrailmod.blocks;
public class HungArrowSign extends ArrowSign {
public HungArrowSign(Material materialIn) {
super(Material.IRON);
this.setUnlocalizedName("hung_arrow_sign"); | this.setCreativeTab(TransitRailMod.tabTransitRail); |
cthbleachbit/TransitRailMod | src/main/java/tk/cth451/transitrailmod/blocks/prototype/EntityDetector.java | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
| import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.TransitRailMod; | package tk.cth451.transitrailmod.blocks.prototype;
public abstract class EntityDetector extends CustomDirectionBlock {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public static final PropertyBool POWERED = PropertyBool.create("powered");
public EntityDetector(Material materialIn) {
super(materialIn);
this.setTickRandomly(true); | // Path: src/main/java/tk/cth451/transitrailmod/TransitRailMod.java
// @Mod(modid = References.MOD_ID, version = References.VERSION, name = References.VERSION)
// public class TransitRailMod
// {
// @Instance(References.MOD_ID)
// public static TransitRailMod instance;
//
// @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
// public static CommonProxy proxy;
//
// public static final TransitRailTab tabTransitRail = new TransitRailTab("tabTransitRail");
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent event)
// {
// ModBlocks.init();
// ModBlocks.register();
// ModItems.init();
// ModItems.register();
// ModTileEntities.register();
// }
//
// @EventHandler
// public void init(FMLInitializationEvent event)
// {
// ModRecipe.addItemsRecipe();
// ModRecipe.addBlocksRecipe();
// proxy.registerRenders();
// NetworkRegistry.INSTANCE.registerGuiHandler(TransitRailMod.instance, new ModGuiHandler());
// }
//
// @EventHandler
// public void postInit(FMLPostInitializationEvent event)
// {
//
// }
// }
// Path: src/main/java/tk/cth451/transitrailmod/blocks/prototype/EntityDetector.java
import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tk.cth451.transitrailmod.TransitRailMod;
package tk.cth451.transitrailmod.blocks.prototype;
public abstract class EntityDetector extends CustomDirectionBlock {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public static final PropertyBool POWERED = PropertyBool.create("powered");
public EntityDetector(Material materialIn) {
super(materialIn);
this.setTickRandomly(true); | this.setCreativeTab(TransitRailMod.tabTransitRail); |
rainu/telegram-bot-api | src/main/java/de/raysha/lib/telegram/bot/api/UnirestRequestExecutor.java | // Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotApiException.java
// public class BotApiException extends BotException {
//
// /**
// * Similar to HTTP status. Contains information on the type of error that occurred: for example,
// * a data input error, privacy error, or server error.
// */
// private int errorCode;
//
// /**
// * A string literal in the form of /[A-Z_0-9]+/, which summarizes the problem. For example, AUTH_KEY_UNREGISTERED.
// *
// * Optional, could be null
// */
// private String errorType;
//
// /**
// * May contain more detailed information on the error and how to resolve it, for example: authorization required,
// * use auth.* methods. Please note that the description text is subject to change, one should avoid tying
// * application logic to these messages.
// *
// * Optional, could be null
// */
// private String description;
//
// public BotApiException(int errorCode, String errorType, String description, Throwable cause) {
// super(cause);
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public BotApiException(int errorCode, String errorType, String description) {
// super();
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public int getErrorCode() {
// return errorCode;
// }
//
// public String getErrorType() {
// return errorType;
// }
//
// public String getDescription() {
// return description;
// }
//
// @Override
// public String getMessage() {
// StringBuilder buf = new StringBuilder();
// buf.append(errorCode);
// if (errorType != null) {
// buf.append(' ').append(errorType);
// }
// if (description != null) {
// buf.append(" '").append(description).append('\'');
// }
// return buf.toString();
// }
// }
//
// Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotException.java
// public class BotException extends Exception {
//
// public BotException() {
// }
//
// public BotException(String message) {
// super(message);
// }
//
// public BotException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public BotException(Throwable cause) {
// super(cause);
// }
//
// public BotException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.BaseRequest;
import de.raysha.lib.telegram.bot.api.exception.BotApiException;
import de.raysha.lib.telegram.bot.api.exception.BotException;
import org.json.JSONObject;
import java.io.File;
import java.util.Map; | package de.raysha.lib.telegram.bot.api;
/**
* Uses Unirest lib for making http requests
*/
public class UnirestRequestExecutor implements RequestExecutor {
private final String baseUrl;
public UnirestRequestExecutor(String baseUrl) {
this.baseUrl = baseUrl;
}
@Override | // Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotApiException.java
// public class BotApiException extends BotException {
//
// /**
// * Similar to HTTP status. Contains information on the type of error that occurred: for example,
// * a data input error, privacy error, or server error.
// */
// private int errorCode;
//
// /**
// * A string literal in the form of /[A-Z_0-9]+/, which summarizes the problem. For example, AUTH_KEY_UNREGISTERED.
// *
// * Optional, could be null
// */
// private String errorType;
//
// /**
// * May contain more detailed information on the error and how to resolve it, for example: authorization required,
// * use auth.* methods. Please note that the description text is subject to change, one should avoid tying
// * application logic to these messages.
// *
// * Optional, could be null
// */
// private String description;
//
// public BotApiException(int errorCode, String errorType, String description, Throwable cause) {
// super(cause);
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public BotApiException(int errorCode, String errorType, String description) {
// super();
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public int getErrorCode() {
// return errorCode;
// }
//
// public String getErrorType() {
// return errorType;
// }
//
// public String getDescription() {
// return description;
// }
//
// @Override
// public String getMessage() {
// StringBuilder buf = new StringBuilder();
// buf.append(errorCode);
// if (errorType != null) {
// buf.append(' ').append(errorType);
// }
// if (description != null) {
// buf.append(" '").append(description).append('\'');
// }
// return buf.toString();
// }
// }
//
// Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotException.java
// public class BotException extends Exception {
//
// public BotException() {
// }
//
// public BotException(String message) {
// super(message);
// }
//
// public BotException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public BotException(Throwable cause) {
// super(cause);
// }
//
// public BotException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/de/raysha/lib/telegram/bot/api/UnirestRequestExecutor.java
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.BaseRequest;
import de.raysha.lib.telegram.bot.api.exception.BotApiException;
import de.raysha.lib.telegram.bot.api.exception.BotException;
import org.json.JSONObject;
import java.io.File;
import java.util.Map;
package de.raysha.lib.telegram.bot.api;
/**
* Uses Unirest lib for making http requests
*/
public class UnirestRequestExecutor implements RequestExecutor {
private final String baseUrl;
public UnirestRequestExecutor(String baseUrl) {
this.baseUrl = baseUrl;
}
@Override | public String get(String action, Map<String, Object> parameters) throws BotException { |
rainu/telegram-bot-api | src/main/java/de/raysha/lib/telegram/bot/api/UnirestRequestExecutor.java | // Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotApiException.java
// public class BotApiException extends BotException {
//
// /**
// * Similar to HTTP status. Contains information on the type of error that occurred: for example,
// * a data input error, privacy error, or server error.
// */
// private int errorCode;
//
// /**
// * A string literal in the form of /[A-Z_0-9]+/, which summarizes the problem. For example, AUTH_KEY_UNREGISTERED.
// *
// * Optional, could be null
// */
// private String errorType;
//
// /**
// * May contain more detailed information on the error and how to resolve it, for example: authorization required,
// * use auth.* methods. Please note that the description text is subject to change, one should avoid tying
// * application logic to these messages.
// *
// * Optional, could be null
// */
// private String description;
//
// public BotApiException(int errorCode, String errorType, String description, Throwable cause) {
// super(cause);
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public BotApiException(int errorCode, String errorType, String description) {
// super();
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public int getErrorCode() {
// return errorCode;
// }
//
// public String getErrorType() {
// return errorType;
// }
//
// public String getDescription() {
// return description;
// }
//
// @Override
// public String getMessage() {
// StringBuilder buf = new StringBuilder();
// buf.append(errorCode);
// if (errorType != null) {
// buf.append(' ').append(errorType);
// }
// if (description != null) {
// buf.append(" '").append(description).append('\'');
// }
// return buf.toString();
// }
// }
//
// Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotException.java
// public class BotException extends Exception {
//
// public BotException() {
// }
//
// public BotException(String message) {
// super(message);
// }
//
// public BotException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public BotException(Throwable cause) {
// super(cause);
// }
//
// public BotException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.BaseRequest;
import de.raysha.lib.telegram.bot.api.exception.BotApiException;
import de.raysha.lib.telegram.bot.api.exception.BotException;
import org.json.JSONObject;
import java.io.File;
import java.util.Map; | return sendAndHandleRequest(
Unirest.get(baseUrl + action)
.queryString(parameters));
}
@Override
public String post(String action, Map<String, Object> parameters) throws BotException {
return sendAndHandleRequest(
Unirest.post(baseUrl + action)
.fields(parameters));
}
@Override
public String post(String action, Map<String, Object> parameters, String fileName, File file) throws BotException {
return sendAndHandleRequest(
Unirest.post(baseUrl + action)
.queryString(parameters)
.field(fileName, file));
}
private String sendAndHandleRequest(BaseRequest request) throws BotException {
JSONObject jsonResult;
try {
jsonResult = request
.asJson().getBody().getObject();
} catch (UnirestException e) {
throw new BotException("Could not get a response.", e);
}
if(jsonResult.get("ok").equals(false)){ | // Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotApiException.java
// public class BotApiException extends BotException {
//
// /**
// * Similar to HTTP status. Contains information on the type of error that occurred: for example,
// * a data input error, privacy error, or server error.
// */
// private int errorCode;
//
// /**
// * A string literal in the form of /[A-Z_0-9]+/, which summarizes the problem. For example, AUTH_KEY_UNREGISTERED.
// *
// * Optional, could be null
// */
// private String errorType;
//
// /**
// * May contain more detailed information on the error and how to resolve it, for example: authorization required,
// * use auth.* methods. Please note that the description text is subject to change, one should avoid tying
// * application logic to these messages.
// *
// * Optional, could be null
// */
// private String description;
//
// public BotApiException(int errorCode, String errorType, String description, Throwable cause) {
// super(cause);
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public BotApiException(int errorCode, String errorType, String description) {
// super();
// this.errorCode = errorCode;
// this.errorType = errorType;
// this.description = description;
// }
//
// public int getErrorCode() {
// return errorCode;
// }
//
// public String getErrorType() {
// return errorType;
// }
//
// public String getDescription() {
// return description;
// }
//
// @Override
// public String getMessage() {
// StringBuilder buf = new StringBuilder();
// buf.append(errorCode);
// if (errorType != null) {
// buf.append(' ').append(errorType);
// }
// if (description != null) {
// buf.append(" '").append(description).append('\'');
// }
// return buf.toString();
// }
// }
//
// Path: src/main/java/de/raysha/lib/telegram/bot/api/exception/BotException.java
// public class BotException extends Exception {
//
// public BotException() {
// }
//
// public BotException(String message) {
// super(message);
// }
//
// public BotException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public BotException(Throwable cause) {
// super(cause);
// }
//
// public BotException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/de/raysha/lib/telegram/bot/api/UnirestRequestExecutor.java
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.BaseRequest;
import de.raysha.lib.telegram.bot.api.exception.BotApiException;
import de.raysha.lib.telegram.bot.api.exception.BotException;
import org.json.JSONObject;
import java.io.File;
import java.util.Map;
return sendAndHandleRequest(
Unirest.get(baseUrl + action)
.queryString(parameters));
}
@Override
public String post(String action, Map<String, Object> parameters) throws BotException {
return sendAndHandleRequest(
Unirest.post(baseUrl + action)
.fields(parameters));
}
@Override
public String post(String action, Map<String, Object> parameters, String fileName, File file) throws BotException {
return sendAndHandleRequest(
Unirest.post(baseUrl + action)
.queryString(parameters)
.field(fileName, file));
}
private String sendAndHandleRequest(BaseRequest request) throws BotException {
JSONObject jsonResult;
try {
jsonResult = request
.asJson().getBody().getObject();
} catch (UnirestException e) {
throw new BotException("Could not get a response.", e);
}
if(jsonResult.get("ok").equals(false)){ | throw new BotApiException( |
jbosgi/jbosgi-repository | core/src/main/java/org/jboss/osgi/repository/AttributeValueHandler.java | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// enum Type {
// String,
// Version,
// Long,
// Double
// }
| import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import java.util.ArrayList;
import java.util.List;
import org.jboss.osgi.repository.Namespace100.Type;
import org.osgi.framework.Version; | /*
* #%L
* JBossOSGi Repository: API
* %%
* Copyright (C) 2011 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.osgi.repository;
/**
* A handler for attribute values.
*
* @author thomas.diesler@jboss.com
* @since 06-Jul-2012
*/
public final class AttributeValueHandler {
/**
* Read attribute values according to
* 132.5.6 Attribute Element
*/
public static AttributeValue readAttributeValue(String typespec, String valstr) {
boolean listType = false;
if (typespec != null && typespec.startsWith("List<") && typespec.endsWith(">")) {
typespec = typespec.substring(5, typespec.length() - 1);
listType = true;
} | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// Path: core/src/main/java/org/jboss/osgi/repository/AttributeValueHandler.java
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import java.util.ArrayList;
import java.util.List;
import org.jboss.osgi.repository.Namespace100.Type;
import org.osgi.framework.Version;
/*
* #%L
* JBossOSGi Repository: API
* %%
* Copyright (C) 2011 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.osgi.repository;
/**
* A handler for attribute values.
*
* @author thomas.diesler@jboss.com
* @since 06-Jul-2012
*/
public final class AttributeValueHandler {
/**
* Read attribute values according to
* 132.5.6 Attribute Element
*/
public static AttributeValue readAttributeValue(String typespec, String valstr) {
boolean listType = false;
if (typespec != null && typespec.startsWith("List<") && typespec.endsWith(">")) {
typespec = typespec.substring(5, typespec.length() - 1);
listType = true;
} | Type type = typespec != null ? Type.valueOf(typespec) : Type.String; |
jbosgi/jbosgi-repository | core/src/test/java/org/jboss/test/osgi/repository/AbstractResourcesReaderTestCase.java | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// public interface Namespace100 {
//
// String REPOSITORY_NAMESPACE = "http://www.osgi.org/xmlns/repository/v1.0.0";
//
// enum Attribute {
// UNKNOWN(null),
// NAME("name"),
// NAMESPACE("namespace"),
// INCREMENT("increment"),
// VALUE("value"),
// TYPE("type"),
// ;
// private final String name;
//
// Attribute(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Attribute> MAP;
//
// static {
// final Map<String, Attribute> map = new HashMap<String, Attribute>();
// for (Attribute element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Attribute forName(String localName) {
// final Attribute element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
//
// public String toString() {
// return getLocalName();
// }
// }
//
// enum Element {
// UNKNOWN(null),
// ATTRIBUTE("attribute"),
// CAPABILITY("capability"),
// DIRECTIVE("directive"),
// REQUIREMENT("requirement"),
// REPOSITORY("repository"),
// RESOURCE("resource"),
// ;
//
// private final String name;
//
// Element(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Element> MAP;
//
// static {
// final Map<String, Element> map = new HashMap<String, Element>();
// for (Element element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Element forName(String localName) {
// final Element element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
// }
//
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/osgi/service/repository/RepositoryContent.java
// @ProviderType
// public interface RepositoryContent {
//
// /**
// * Returns a new input stream to the default format of this resource.
// *
// * @return A new input stream for associated resource.
// */
// InputStream getContent();
// }
| import org.osgi.service.repository.RepositoryContent;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.jboss.osgi.repository.Namespace100;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.junit.Test;
import org.osgi.framework.Version; | package org.jboss.test.osgi.repository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Test the abstract resource reader/writer
*
* @author thomas.diesler@jboss.com
* @since 21-May-2012
*/
public class AbstractResourcesReaderTestCase extends AbstractRepositoryTest {
@Test
public void testXMLReader() throws Exception { | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// public interface Namespace100 {
//
// String REPOSITORY_NAMESPACE = "http://www.osgi.org/xmlns/repository/v1.0.0";
//
// enum Attribute {
// UNKNOWN(null),
// NAME("name"),
// NAMESPACE("namespace"),
// INCREMENT("increment"),
// VALUE("value"),
// TYPE("type"),
// ;
// private final String name;
//
// Attribute(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Attribute> MAP;
//
// static {
// final Map<String, Attribute> map = new HashMap<String, Attribute>();
// for (Attribute element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Attribute forName(String localName) {
// final Attribute element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
//
// public String toString() {
// return getLocalName();
// }
// }
//
// enum Element {
// UNKNOWN(null),
// ATTRIBUTE("attribute"),
// CAPABILITY("capability"),
// DIRECTIVE("directive"),
// REQUIREMENT("requirement"),
// REPOSITORY("repository"),
// RESOURCE("resource"),
// ;
//
// private final String name;
//
// Element(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Element> MAP;
//
// static {
// final Map<String, Element> map = new HashMap<String, Element>();
// for (Element element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Element forName(String localName) {
// final Element element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
// }
//
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/osgi/service/repository/RepositoryContent.java
// @ProviderType
// public interface RepositoryContent {
//
// /**
// * Returns a new input stream to the default format of this resource.
// *
// * @return A new input stream for associated resource.
// */
// InputStream getContent();
// }
// Path: core/src/test/java/org/jboss/test/osgi/repository/AbstractResourcesReaderTestCase.java
import org.osgi.service.repository.RepositoryContent;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.jboss.osgi.repository.Namespace100;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.junit.Test;
import org.osgi.framework.Version;
package org.jboss.test.osgi.repository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Test the abstract resource reader/writer
*
* @author thomas.diesler@jboss.com
* @since 21-May-2012
*/
public class AbstractResourcesReaderTestCase extends AbstractRepositoryTest {
@Test
public void testXMLReader() throws Exception { | RepositoryReader reader = getRepositoryReader("xml/abstract-resources.xml"); |
jbosgi/jbosgi-repository | core/src/test/java/org/jboss/test/osgi/repository/AbstractResourcesReaderTestCase.java | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// public interface Namespace100 {
//
// String REPOSITORY_NAMESPACE = "http://www.osgi.org/xmlns/repository/v1.0.0";
//
// enum Attribute {
// UNKNOWN(null),
// NAME("name"),
// NAMESPACE("namespace"),
// INCREMENT("increment"),
// VALUE("value"),
// TYPE("type"),
// ;
// private final String name;
//
// Attribute(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Attribute> MAP;
//
// static {
// final Map<String, Attribute> map = new HashMap<String, Attribute>();
// for (Attribute element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Attribute forName(String localName) {
// final Attribute element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
//
// public String toString() {
// return getLocalName();
// }
// }
//
// enum Element {
// UNKNOWN(null),
// ATTRIBUTE("attribute"),
// CAPABILITY("capability"),
// DIRECTIVE("directive"),
// REQUIREMENT("requirement"),
// REPOSITORY("repository"),
// RESOURCE("resource"),
// ;
//
// private final String name;
//
// Element(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Element> MAP;
//
// static {
// final Map<String, Element> map = new HashMap<String, Element>();
// for (Element element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Element forName(String localName) {
// final Element element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
// }
//
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/osgi/service/repository/RepositoryContent.java
// @ProviderType
// public interface RepositoryContent {
//
// /**
// * Returns a new input stream to the default format of this resource.
// *
// * @return A new input stream for associated resource.
// */
// InputStream getContent();
// }
| import org.osgi.service.repository.RepositoryContent;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.jboss.osgi.repository.Namespace100;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.junit.Test;
import org.osgi.framework.Version; | package org.jboss.test.osgi.repository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Test the abstract resource reader/writer
*
* @author thomas.diesler@jboss.com
* @since 21-May-2012
*/
public class AbstractResourcesReaderTestCase extends AbstractRepositoryTest {
@Test
public void testXMLReader() throws Exception {
RepositoryReader reader = getRepositoryReader("xml/abstract-resources.xml");
Map<String, String> attributes = reader.getRepositoryAttributes();
List<XResource> resources = getResources(reader);
verifyContent(attributes, resources);
}
static void verifyContent(Map<String, String> attributes, List<XResource> resources) {
Assert.assertEquals("Two attributes", 2, attributes.size()); | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// public interface Namespace100 {
//
// String REPOSITORY_NAMESPACE = "http://www.osgi.org/xmlns/repository/v1.0.0";
//
// enum Attribute {
// UNKNOWN(null),
// NAME("name"),
// NAMESPACE("namespace"),
// INCREMENT("increment"),
// VALUE("value"),
// TYPE("type"),
// ;
// private final String name;
//
// Attribute(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Attribute> MAP;
//
// static {
// final Map<String, Attribute> map = new HashMap<String, Attribute>();
// for (Attribute element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Attribute forName(String localName) {
// final Attribute element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
//
// public String toString() {
// return getLocalName();
// }
// }
//
// enum Element {
// UNKNOWN(null),
// ATTRIBUTE("attribute"),
// CAPABILITY("capability"),
// DIRECTIVE("directive"),
// REQUIREMENT("requirement"),
// REPOSITORY("repository"),
// RESOURCE("resource"),
// ;
//
// private final String name;
//
// Element(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Element> MAP;
//
// static {
// final Map<String, Element> map = new HashMap<String, Element>();
// for (Element element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Element forName(String localName) {
// final Element element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
// }
//
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/osgi/service/repository/RepositoryContent.java
// @ProviderType
// public interface RepositoryContent {
//
// /**
// * Returns a new input stream to the default format of this resource.
// *
// * @return A new input stream for associated resource.
// */
// InputStream getContent();
// }
// Path: core/src/test/java/org/jboss/test/osgi/repository/AbstractResourcesReaderTestCase.java
import org.osgi.service.repository.RepositoryContent;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.jboss.osgi.repository.Namespace100;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.junit.Test;
import org.osgi.framework.Version;
package org.jboss.test.osgi.repository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Test the abstract resource reader/writer
*
* @author thomas.diesler@jboss.com
* @since 21-May-2012
*/
public class AbstractResourcesReaderTestCase extends AbstractRepositoryTest {
@Test
public void testXMLReader() throws Exception {
RepositoryReader reader = getRepositoryReader("xml/abstract-resources.xml");
Map<String, String> attributes = reader.getRepositoryAttributes();
List<XResource> resources = getResources(reader);
verifyContent(attributes, resources);
}
static void verifyContent(Map<String, String> attributes, List<XResource> resources) {
Assert.assertEquals("Two attributes", 2, attributes.size()); | Assert.assertEquals("OSGi Repository", attributes.get(Namespace100.Attribute.NAME.getLocalName())); |
jbosgi/jbosgi-repository | core/src/test/java/org/jboss/test/osgi/repository/AbstractResourcesReaderTestCase.java | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// public interface Namespace100 {
//
// String REPOSITORY_NAMESPACE = "http://www.osgi.org/xmlns/repository/v1.0.0";
//
// enum Attribute {
// UNKNOWN(null),
// NAME("name"),
// NAMESPACE("namespace"),
// INCREMENT("increment"),
// VALUE("value"),
// TYPE("type"),
// ;
// private final String name;
//
// Attribute(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Attribute> MAP;
//
// static {
// final Map<String, Attribute> map = new HashMap<String, Attribute>();
// for (Attribute element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Attribute forName(String localName) {
// final Attribute element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
//
// public String toString() {
// return getLocalName();
// }
// }
//
// enum Element {
// UNKNOWN(null),
// ATTRIBUTE("attribute"),
// CAPABILITY("capability"),
// DIRECTIVE("directive"),
// REQUIREMENT("requirement"),
// REPOSITORY("repository"),
// RESOURCE("resource"),
// ;
//
// private final String name;
//
// Element(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Element> MAP;
//
// static {
// final Map<String, Element> map = new HashMap<String, Element>();
// for (Element element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Element forName(String localName) {
// final Element element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
// }
//
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/osgi/service/repository/RepositoryContent.java
// @ProviderType
// public interface RepositoryContent {
//
// /**
// * Returns a new input stream to the default format of this resource.
// *
// * @return A new input stream for associated resource.
// */
// InputStream getContent();
// }
| import org.osgi.service.repository.RepositoryContent;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.jboss.osgi.repository.Namespace100;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.junit.Test;
import org.osgi.framework.Version; | package org.jboss.test.osgi.repository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Test the abstract resource reader/writer
*
* @author thomas.diesler@jboss.com
* @since 21-May-2012
*/
public class AbstractResourcesReaderTestCase extends AbstractRepositoryTest {
@Test
public void testXMLReader() throws Exception {
RepositoryReader reader = getRepositoryReader("xml/abstract-resources.xml");
Map<String, String> attributes = reader.getRepositoryAttributes();
List<XResource> resources = getResources(reader);
verifyContent(attributes, resources);
}
static void verifyContent(Map<String, String> attributes, List<XResource> resources) {
Assert.assertEquals("Two attributes", 2, attributes.size());
Assert.assertEquals("OSGi Repository", attributes.get(Namespace100.Attribute.NAME.getLocalName()));
Assert.assertEquals("1", attributes.get(Namespace100.Attribute.INCREMENT.getLocalName()));
Assert.assertEquals("One resource", 1, resources.size());
XResource resource = resources.get(0);
Assert.assertNotNull("Resource not null", resource); | // Path: core/src/main/java/org/jboss/osgi/repository/Namespace100.java
// public interface Namespace100 {
//
// String REPOSITORY_NAMESPACE = "http://www.osgi.org/xmlns/repository/v1.0.0";
//
// enum Attribute {
// UNKNOWN(null),
// NAME("name"),
// NAMESPACE("namespace"),
// INCREMENT("increment"),
// VALUE("value"),
// TYPE("type"),
// ;
// private final String name;
//
// Attribute(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Attribute> MAP;
//
// static {
// final Map<String, Attribute> map = new HashMap<String, Attribute>();
// for (Attribute element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Attribute forName(String localName) {
// final Attribute element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
//
// public String toString() {
// return getLocalName();
// }
// }
//
// enum Element {
// UNKNOWN(null),
// ATTRIBUTE("attribute"),
// CAPABILITY("capability"),
// DIRECTIVE("directive"),
// REQUIREMENT("requirement"),
// REPOSITORY("repository"),
// RESOURCE("resource"),
// ;
//
// private final String name;
//
// Element(final String name) {
// this.name = name;
// }
//
// public String getLocalName() {
// return name;
// }
//
// private static final Map<String, Element> MAP;
//
// static {
// final Map<String, Element> map = new HashMap<String, Element>();
// for (Element element : values()) {
// final String name = element.getLocalName();
// if (name != null) map.put(name, element);
// }
// MAP = map;
// }
//
// public static Element forName(String localName) {
// final Element element = MAP.get(localName);
// return element == null ? UNKNOWN : element;
// }
// }
//
// enum Type {
// String,
// Version,
// Long,
// Double
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/osgi/service/repository/RepositoryContent.java
// @ProviderType
// public interface RepositoryContent {
//
// /**
// * Returns a new input stream to the default format of this resource.
// *
// * @return A new input stream for associated resource.
// */
// InputStream getContent();
// }
// Path: core/src/test/java/org/jboss/test/osgi/repository/AbstractResourcesReaderTestCase.java
import org.osgi.service.repository.RepositoryContent;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.jboss.osgi.repository.Namespace100;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.junit.Test;
import org.osgi.framework.Version;
package org.jboss.test.osgi.repository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Test the abstract resource reader/writer
*
* @author thomas.diesler@jboss.com
* @since 21-May-2012
*/
public class AbstractResourcesReaderTestCase extends AbstractRepositoryTest {
@Test
public void testXMLReader() throws Exception {
RepositoryReader reader = getRepositoryReader("xml/abstract-resources.xml");
Map<String, String> attributes = reader.getRepositoryAttributes();
List<XResource> resources = getResources(reader);
verifyContent(attributes, resources);
}
static void verifyContent(Map<String, String> attributes, List<XResource> resources) {
Assert.assertEquals("Two attributes", 2, attributes.size());
Assert.assertEquals("OSGi Repository", attributes.get(Namespace100.Attribute.NAME.getLocalName()));
Assert.assertEquals("1", attributes.get(Namespace100.Attribute.INCREMENT.getLocalName()));
Assert.assertEquals("One resource", 1, resources.size());
XResource resource = resources.get(0);
Assert.assertNotNull("Resource not null", resource); | Assert.assertFalse("No RepositoryContent", resource instanceof RepositoryContent); |
jbosgi/jbosgi-repository | itests/src/test/java/org/jboss/test/osgi/repository/AbstractRepositoryTest.java | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
| import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference; | /*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.osgi.repository;
/**
* Test OSGi repository access
*
* @author thomas.diesler@jboss.com
* @since 31-May-2012
*/
public abstract class AbstractRepositoryTest {
private static final AtomicBoolean initialized = new AtomicBoolean();
@ArquillianResource
BundleContext context;
@Before
public void setUp () throws Exception {
if (initialized.compareAndSet(false, true)) {
initializeRepository(getRepository());
}
}
| // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
// Path: itests/src/test/java/org/jboss/test/osgi/repository/AbstractRepositoryTest.java
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.osgi.repository;
/**
* Test OSGi repository access
*
* @author thomas.diesler@jboss.com
* @since 31-May-2012
*/
public abstract class AbstractRepositoryTest {
private static final AtomicBoolean initialized = new AtomicBoolean();
@ArquillianResource
BundleContext context;
@Before
public void setUp () throws Exception {
if (initialized.compareAndSet(false, true)) {
initializeRepository(getRepository());
}
}
| protected void initializeRepository(XRepository repo) throws Exception { |
jbosgi/jbosgi-repository | itests/src/test/java/org/jboss/test/osgi/repository/AbstractRepositoryTest.java | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
| import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference; | /*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.osgi.repository;
/**
* Test OSGi repository access
*
* @author thomas.diesler@jboss.com
* @since 31-May-2012
*/
public abstract class AbstractRepositoryTest {
private static final AtomicBoolean initialized = new AtomicBoolean();
@ArquillianResource
BundleContext context;
@Before
public void setUp () throws Exception {
if (initialized.compareAndSet(false, true)) {
initializeRepository(getRepository());
}
}
protected void initializeRepository(XRepository repo) throws Exception {
// Remove all resources from storage | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
// Path: itests/src/test/java/org/jboss/test/osgi/repository/AbstractRepositoryTest.java
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.osgi.repository;
/**
* Test OSGi repository access
*
* @author thomas.diesler@jboss.com
* @since 31-May-2012
*/
public abstract class AbstractRepositoryTest {
private static final AtomicBoolean initialized = new AtomicBoolean();
@ArquillianResource
BundleContext context;
@Before
public void setUp () throws Exception {
if (initialized.compareAndSet(false, true)) {
initializeRepository(getRepository());
}
}
protected void initializeRepository(XRepository repo) throws Exception {
// Remove all resources from storage | RepositoryStorage storage = repo.adapt(RepositoryStorage.class); |
jbosgi/jbosgi-repository | itests/src/test/java/org/jboss/test/osgi/repository/AbstractRepositoryTest.java | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
| import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference; | /*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.osgi.repository;
/**
* Test OSGi repository access
*
* @author thomas.diesler@jboss.com
* @since 31-May-2012
*/
public abstract class AbstractRepositoryTest {
private static final AtomicBoolean initialized = new AtomicBoolean();
@ArquillianResource
BundleContext context;
@Before
public void setUp () throws Exception {
if (initialized.compareAndSet(false, true)) {
initializeRepository(getRepository());
}
}
protected void initializeRepository(XRepository repo) throws Exception {
// Remove all resources from storage
RepositoryStorage storage = repo.adapt(RepositoryStorage.class);
if (storage != null) { | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
// Path: itests/src/test/java/org/jboss/test/osgi/repository/AbstractRepositoryTest.java
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.test.osgi.repository;
/**
* Test OSGi repository access
*
* @author thomas.diesler@jboss.com
* @since 31-May-2012
*/
public abstract class AbstractRepositoryTest {
private static final AtomicBoolean initialized = new AtomicBoolean();
@ArquillianResource
BundleContext context;
@Before
public void setUp () throws Exception {
if (initialized.compareAndSet(false, true)) {
initializeRepository(getRepository());
}
}
protected void initializeRepository(XRepository repo) throws Exception {
// Remove all resources from storage
RepositoryStorage storage = repo.adapt(RepositoryStorage.class);
if (storage != null) { | RepositoryReader reader = storage.getRepositoryReader(); |
jbosgi/jbosgi-repository | core/src/main/java/org/jboss/osgi/repository/spi/MemoryRepositoryStorage.java | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageException.java
// public class RepositoryStorageException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public RepositoryStorageException(String message) {
// super(message);
// }
//
// public RepositoryStorageException(Throwable cause) {
// super(cause);
// }
//
// public RepositoryStorageException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageFactory.java
// public interface RepositoryStorageFactory {
//
// /**
// * Create the storage for a given repository
// *
// * @param repository The associated repository
// */
// RepositoryStorage create(XRepository repository);
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
| import static org.jboss.osgi.repository.RepositoryLogger.LOGGER;
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import static org.osgi.framework.namespace.IdentityNamespace.IDENTITY_NAMESPACE;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.RepositoryStorageException;
import org.jboss.osgi.repository.RepositoryStorageFactory;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XCapability;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XRequirement;
import org.jboss.osgi.resolver.XResource;
import org.jboss.osgi.resolver.spi.AbstractRequirement;
import org.osgi.framework.Filter;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource; |
@Override
public Map<String, String> getRepositoryAttributes() {
HashMap<String, String> attributes = new HashMap<String, String>();
attributes.put("name", getRepository().getName());
attributes.put("increment", new Long(increment.get()).toString());
return Collections.unmodifiableMap(attributes);
}
@Override
public XResource nextResource() {
return iterator.hasNext() ? iterator.next() : null;
}
@Override
public void close() {
// do nothing
}
};
}
}
@Override
public synchronized Collection<Capability> findProviders(Requirement req) {
Set<Capability> result = findCachedProviders(req);
LOGGER.tracef("Find cached providers: %s => %s", req, result);
return result;
}
@Override | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryReader.java
// public interface RepositoryReader {
//
// Map<String, String> getRepositoryAttributes();
//
// XResource nextResource();
//
// void close();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageException.java
// public class RepositoryStorageException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public RepositoryStorageException(String message) {
// super(message);
// }
//
// public RepositoryStorageException(Throwable cause) {
// super(cause);
// }
//
// public RepositoryStorageException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageFactory.java
// public interface RepositoryStorageFactory {
//
// /**
// * Create the storage for a given repository
// *
// * @param repository The associated repository
// */
// RepositoryStorage create(XRepository repository);
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
// Path: core/src/main/java/org/jboss/osgi/repository/spi/MemoryRepositoryStorage.java
import static org.jboss.osgi.repository.RepositoryLogger.LOGGER;
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import static org.osgi.framework.namespace.IdentityNamespace.IDENTITY_NAMESPACE;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.osgi.repository.RepositoryReader;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.RepositoryStorageException;
import org.jboss.osgi.repository.RepositoryStorageFactory;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XCapability;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XRequirement;
import org.jboss.osgi.resolver.XResource;
import org.jboss.osgi.resolver.spi.AbstractRequirement;
import org.osgi.framework.Filter;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
@Override
public Map<String, String> getRepositoryAttributes() {
HashMap<String, String> attributes = new HashMap<String, String>();
attributes.put("name", getRepository().getName());
attributes.put("increment", new Long(increment.get()).toString());
return Collections.unmodifiableMap(attributes);
}
@Override
public XResource nextResource() {
return iterator.hasNext() ? iterator.next() : null;
}
@Override
public void close() {
// do nothing
}
};
}
}
@Override
public synchronized Collection<Capability> findProviders(Requirement req) {
Set<Capability> result = findCachedProviders(req);
LOGGER.tracef("Find cached providers: %s => %s", req, result);
return result;
}
@Override | public synchronized XResource addResource(XResource res) throws RepositoryStorageException { |
jbosgi/jbosgi-repository | core/src/main/java/org/jboss/osgi/repository/spi/AbstractPersistentRepository.java | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageFactory.java
// public interface RepositoryStorageFactory {
//
// /**
// * Create the storage for a given repository
// *
// * @param repository The associated repository
// */
// RepositoryStorage create(XRepository repository);
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XPersistentRepository.java
// public interface XPersistentRepository extends XRepository {
//
// void addRepositoryDelegate(XRepository delegate);
//
// void removeRepositoryDelegate(XRepository delegate);
//
// List<XRepository> getRepositoryDelegates();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
| import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import static org.jboss.osgi.repository.RepositoryLogger.LOGGER;
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.RepositoryStorageFactory;
import org.jboss.osgi.repository.XPersistentRepository; | /*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.osgi.repository.spi;
/**
* A {@link XRepository} that delegates to {@link RepositoryStorage}.
*
* @author thomas.diesler@jboss.com
* @since 11-May-2012
*/
public class AbstractPersistentRepository extends AbstractRepository implements XPersistentRepository {
private final RepositoryStorage storage; | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageFactory.java
// public interface RepositoryStorageFactory {
//
// /**
// * Create the storage for a given repository
// *
// * @param repository The associated repository
// */
// RepositoryStorage create(XRepository repository);
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XPersistentRepository.java
// public interface XPersistentRepository extends XRepository {
//
// void addRepositoryDelegate(XRepository delegate);
//
// void removeRepositoryDelegate(XRepository delegate);
//
// List<XRepository> getRepositoryDelegates();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
// Path: core/src/main/java/org/jboss/osgi/repository/spi/AbstractPersistentRepository.java
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import static org.jboss.osgi.repository.RepositoryLogger.LOGGER;
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.RepositoryStorageFactory;
import org.jboss.osgi.repository.XPersistentRepository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.osgi.repository.spi;
/**
* A {@link XRepository} that delegates to {@link RepositoryStorage}.
*
* @author thomas.diesler@jboss.com
* @since 11-May-2012
*/
public class AbstractPersistentRepository extends AbstractRepository implements XPersistentRepository {
private final RepositoryStorage storage; | private final List<XRepository> delegates = new ArrayList<XRepository>(); |
jbosgi/jbosgi-repository | core/src/main/java/org/jboss/osgi/repository/spi/AbstractPersistentRepository.java | // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageFactory.java
// public interface RepositoryStorageFactory {
//
// /**
// * Create the storage for a given repository
// *
// * @param repository The associated repository
// */
// RepositoryStorage create(XRepository repository);
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XPersistentRepository.java
// public interface XPersistentRepository extends XRepository {
//
// void addRepositoryDelegate(XRepository delegate);
//
// void removeRepositoryDelegate(XRepository delegate);
//
// List<XRepository> getRepositoryDelegates();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
| import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import static org.jboss.osgi.repository.RepositoryLogger.LOGGER;
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.RepositoryStorageFactory;
import org.jboss.osgi.repository.XPersistentRepository; | /*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.osgi.repository.spi;
/**
* A {@link XRepository} that delegates to {@link RepositoryStorage}.
*
* @author thomas.diesler@jboss.com
* @since 11-May-2012
*/
public class AbstractPersistentRepository extends AbstractRepository implements XPersistentRepository {
private final RepositoryStorage storage;
private final List<XRepository> delegates = new ArrayList<XRepository>();
| // Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorage.java
// public interface RepositoryStorage {
//
// /**
// * Get the associated reposistory;
// */
// XRepository getRepository();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Get the repository reader for this storage
// */
// RepositoryReader getRepositoryReader();
//
// /**
// * Get the resource for the given identity capability.
// *
// * @return The resource or null
// */
// XResource getResource(XIdentityCapability icap);
//
// /**
// * Add the given resource to storage
// *
// * @param resource The resource to add
// * @return The resource being added, which may be a modified copy of the give resource
// * @throws RepositoryStorageException If there is a problem storing the resource
// */
// XResource addResource(XResource resource) throws RepositoryStorageException;
//
// /**
// * Remove a the given resource from the cache.
// *
// * @param resource The resource to remove
// * @return true if the resource could be found and removed
// * @throws RepositoryStorageException If there is a problem removing the resource from storage
// */
// boolean removeResource(XResource resource) throws RepositoryStorageException;
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/RepositoryStorageFactory.java
// public interface RepositoryStorageFactory {
//
// /**
// * Create the storage for a given repository
// *
// * @param repository The associated repository
// */
// RepositoryStorage create(XRepository repository);
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XPersistentRepository.java
// public interface XPersistentRepository extends XRepository {
//
// void addRepositoryDelegate(XRepository delegate);
//
// void removeRepositoryDelegate(XRepository delegate);
//
// List<XRepository> getRepositoryDelegates();
// }
//
// Path: core/src/main/java/org/jboss/osgi/repository/XRepository.java
// public interface XRepository extends Repository {
//
// /**
// * The property that defines the Maven Repository base URLs.
// */
// String PROPERTY_MAVEN_REPOSITORY_BASE_URLS = "org.jboss.osgi.repository.maven.base.urls";
// /**
// * The property that defines the repository storage directory.
// */
// String PROPERTY_REPOSITORY_STORAGE_DIR = "org.jboss.osgi.repository.storage.dir";
// /**
// * The property that defines the repository storage file.
// */
// String PROPERTY_REPOSITORY_STORAGE_FILE = "org.jboss.osgi.repository.storage.file";
//
// /**
// * Get the name for this repository
// */
// String getName();
//
// /**
// * Find the capabilities that match the specified requirement.
// *
// * @param requirement The requirements for which matching capabilities
// * should be returned. Must not be {@code null}.
// * @return A collection of matching capabilities for the specified requirements.
// * If there are no matching capabilities an empty collection is returned.
// * The returned collection is the property of the caller and can be modified by the caller.
// */
// Collection<Capability> findProviders(Requirement requirement);
//
// /**
// * Adapt this repository tor the given type
// */
// <T> T adapt(Class<T> type);
// }
// Path: core/src/main/java/org/jboss/osgi/repository/spi/AbstractPersistentRepository.java
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XIdentityCapability;
import org.jboss.osgi.resolver.XResource;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import static org.jboss.osgi.repository.RepositoryLogger.LOGGER;
import static org.jboss.osgi.repository.RepositoryMessages.MESSAGES;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.osgi.repository.RepositoryStorage;
import org.jboss.osgi.repository.RepositoryStorageFactory;
import org.jboss.osgi.repository.XPersistentRepository;
/*
* #%L
* JBossOSGi Repository
* %%
* Copyright (C) 2010 - 2012 JBoss by Red Hat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.jboss.osgi.repository.spi;
/**
* A {@link XRepository} that delegates to {@link RepositoryStorage}.
*
* @author thomas.diesler@jboss.com
* @since 11-May-2012
*/
public class AbstractPersistentRepository extends AbstractRepository implements XPersistentRepository {
private final RepositoryStorage storage;
private final List<XRepository> delegates = new ArrayList<XRepository>();
| public AbstractPersistentRepository(RepositoryStorageFactory factory) { |
polysantiago/spring-boot-rest-client | src/main/java/io/github/polysantiago/spring/rest/SyncRequestHelper.java | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryableException.java
// public class RetryableException extends RuntimeException {
//
// public RetryableException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/support/SyntheticParametrizedTypeReference.java
// @Getter
// @EqualsAndHashCode(callSuper = false)
// @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
// public class SyntheticParametrizedTypeReference<T> extends ParameterizedTypeReference<T> {
//
// private final Type type;
//
// public static <T> SyntheticParametrizedTypeReference<T> fromResolvableType(ResolvableType resolvedType) {
// if (resolvedType.hasGenerics()) {
// return new SyntheticParametrizedTypeReference<>(new SyntheticParametrizedType(resolvedType));
// }
// return new SyntheticParametrizedTypeReference<>(resolvedType.resolve());
// }
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/util/ResolvableTypeUtils.java
// @UtilityClass
// public class ResolvableTypeUtils {
//
// public static boolean typeIsAnyOf(ResolvableType resolvableType, Class<?>... classes) {
// return Arrays.stream(classes).anyMatch(clazz -> typeIs(resolvableType, clazz));
// }
//
// public static boolean typeIs(ResolvableType resolvableType, Class<?> clazz) {
// return ResolvableType.forClass(clazz).isAssignableFrom(resolvableType);
// }
//
// public static boolean returnTypeIs(Method method, Class<?> returnType) {
// return ResolvableType.forClass(returnType)
// .isAssignableFrom(ResolvableType.forMethodReturnType(method));
// }
//
// public static boolean returnTypeIsAnyOf(Method method, Class<?>... returnTypes) {
// return Arrays.stream(returnTypes).anyMatch(returnType -> returnTypeIs(method, returnType));
// }
//
// }
| import io.github.polysantiago.spring.rest.retry.RetryableException;
import io.github.polysantiago.spring.rest.support.SyntheticParametrizedTypeReference;
import io.github.polysantiago.spring.rest.util.ResolvableTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause; | package io.github.polysantiago.spring.rest;
@RequiredArgsConstructor
class SyncRequestHelper {
private final RestClientSpecification specification;
private final RestTemplate restTemplate;
private final Class<?> implementingClass;
@Setter
private boolean retryEnabled;
<T> Object executeRequest(MethodInvocation invocation, RequestEntity<T> requestEntity) {
try {
return executeRequestInternal(invocation, requestEntity);
} catch (HttpStatusCodeException ex) {
return handleHttpStatusCodeException(invocation.getMethod(), ex);
} catch (RuntimeException ex) {
throw handleRuntimeException(ex);
}
}
private RuntimeException handleRuntimeException(RuntimeException ex) {
if (retryEnabled && anyMatch(specification.getRetryableExceptions(), clazz -> clazz.isInstance(ex) || clazz.isInstance(getRootCause(ex)))) { | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryableException.java
// public class RetryableException extends RuntimeException {
//
// public RetryableException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/support/SyntheticParametrizedTypeReference.java
// @Getter
// @EqualsAndHashCode(callSuper = false)
// @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
// public class SyntheticParametrizedTypeReference<T> extends ParameterizedTypeReference<T> {
//
// private final Type type;
//
// public static <T> SyntheticParametrizedTypeReference<T> fromResolvableType(ResolvableType resolvedType) {
// if (resolvedType.hasGenerics()) {
// return new SyntheticParametrizedTypeReference<>(new SyntheticParametrizedType(resolvedType));
// }
// return new SyntheticParametrizedTypeReference<>(resolvedType.resolve());
// }
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/util/ResolvableTypeUtils.java
// @UtilityClass
// public class ResolvableTypeUtils {
//
// public static boolean typeIsAnyOf(ResolvableType resolvableType, Class<?>... classes) {
// return Arrays.stream(classes).anyMatch(clazz -> typeIs(resolvableType, clazz));
// }
//
// public static boolean typeIs(ResolvableType resolvableType, Class<?> clazz) {
// return ResolvableType.forClass(clazz).isAssignableFrom(resolvableType);
// }
//
// public static boolean returnTypeIs(Method method, Class<?> returnType) {
// return ResolvableType.forClass(returnType)
// .isAssignableFrom(ResolvableType.forMethodReturnType(method));
// }
//
// public static boolean returnTypeIsAnyOf(Method method, Class<?>... returnTypes) {
// return Arrays.stream(returnTypes).anyMatch(returnType -> returnTypeIs(method, returnType));
// }
//
// }
// Path: src/main/java/io/github/polysantiago/spring/rest/SyncRequestHelper.java
import io.github.polysantiago.spring.rest.retry.RetryableException;
import io.github.polysantiago.spring.rest.support.SyntheticParametrizedTypeReference;
import io.github.polysantiago.spring.rest.util.ResolvableTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
package io.github.polysantiago.spring.rest;
@RequiredArgsConstructor
class SyncRequestHelper {
private final RestClientSpecification specification;
private final RestTemplate restTemplate;
private final Class<?> implementingClass;
@Setter
private boolean retryEnabled;
<T> Object executeRequest(MethodInvocation invocation, RequestEntity<T> requestEntity) {
try {
return executeRequestInternal(invocation, requestEntity);
} catch (HttpStatusCodeException ex) {
return handleHttpStatusCodeException(invocation.getMethod(), ex);
} catch (RuntimeException ex) {
throw handleRuntimeException(ex);
}
}
private RuntimeException handleRuntimeException(RuntimeException ex) {
if (retryEnabled && anyMatch(specification.getRetryableExceptions(), clazz -> clazz.isInstance(ex) || clazz.isInstance(getRootCause(ex)))) { | return new RetryableException(ex); |
polysantiago/spring-boot-rest-client | src/main/java/io/github/polysantiago/spring/rest/SyncRequestHelper.java | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryableException.java
// public class RetryableException extends RuntimeException {
//
// public RetryableException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/support/SyntheticParametrizedTypeReference.java
// @Getter
// @EqualsAndHashCode(callSuper = false)
// @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
// public class SyntheticParametrizedTypeReference<T> extends ParameterizedTypeReference<T> {
//
// private final Type type;
//
// public static <T> SyntheticParametrizedTypeReference<T> fromResolvableType(ResolvableType resolvedType) {
// if (resolvedType.hasGenerics()) {
// return new SyntheticParametrizedTypeReference<>(new SyntheticParametrizedType(resolvedType));
// }
// return new SyntheticParametrizedTypeReference<>(resolvedType.resolve());
// }
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/util/ResolvableTypeUtils.java
// @UtilityClass
// public class ResolvableTypeUtils {
//
// public static boolean typeIsAnyOf(ResolvableType resolvableType, Class<?>... classes) {
// return Arrays.stream(classes).anyMatch(clazz -> typeIs(resolvableType, clazz));
// }
//
// public static boolean typeIs(ResolvableType resolvableType, Class<?> clazz) {
// return ResolvableType.forClass(clazz).isAssignableFrom(resolvableType);
// }
//
// public static boolean returnTypeIs(Method method, Class<?> returnType) {
// return ResolvableType.forClass(returnType)
// .isAssignableFrom(ResolvableType.forMethodReturnType(method));
// }
//
// public static boolean returnTypeIsAnyOf(Method method, Class<?>... returnTypes) {
// return Arrays.stream(returnTypes).anyMatch(returnType -> returnTypeIs(method, returnType));
// }
//
// }
| import io.github.polysantiago.spring.rest.retry.RetryableException;
import io.github.polysantiago.spring.rest.support.SyntheticParametrizedTypeReference;
import io.github.polysantiago.spring.rest.util.ResolvableTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause; | package io.github.polysantiago.spring.rest;
@RequiredArgsConstructor
class SyncRequestHelper {
private final RestClientSpecification specification;
private final RestTemplate restTemplate;
private final Class<?> implementingClass;
@Setter
private boolean retryEnabled;
<T> Object executeRequest(MethodInvocation invocation, RequestEntity<T> requestEntity) {
try {
return executeRequestInternal(invocation, requestEntity);
} catch (HttpStatusCodeException ex) {
return handleHttpStatusCodeException(invocation.getMethod(), ex);
} catch (RuntimeException ex) {
throw handleRuntimeException(ex);
}
}
private RuntimeException handleRuntimeException(RuntimeException ex) {
if (retryEnabled && anyMatch(specification.getRetryableExceptions(), clazz -> clazz.isInstance(ex) || clazz.isInstance(getRootCause(ex)))) {
return new RetryableException(ex);
}
return ex;
}
private <T> Optional<T> handleHttpStatusCodeException(Method method, HttpStatusCodeException ex) {
HttpStatus statusCode = ex.getStatusCode(); | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryableException.java
// public class RetryableException extends RuntimeException {
//
// public RetryableException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/support/SyntheticParametrizedTypeReference.java
// @Getter
// @EqualsAndHashCode(callSuper = false)
// @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
// public class SyntheticParametrizedTypeReference<T> extends ParameterizedTypeReference<T> {
//
// private final Type type;
//
// public static <T> SyntheticParametrizedTypeReference<T> fromResolvableType(ResolvableType resolvedType) {
// if (resolvedType.hasGenerics()) {
// return new SyntheticParametrizedTypeReference<>(new SyntheticParametrizedType(resolvedType));
// }
// return new SyntheticParametrizedTypeReference<>(resolvedType.resolve());
// }
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/util/ResolvableTypeUtils.java
// @UtilityClass
// public class ResolvableTypeUtils {
//
// public static boolean typeIsAnyOf(ResolvableType resolvableType, Class<?>... classes) {
// return Arrays.stream(classes).anyMatch(clazz -> typeIs(resolvableType, clazz));
// }
//
// public static boolean typeIs(ResolvableType resolvableType, Class<?> clazz) {
// return ResolvableType.forClass(clazz).isAssignableFrom(resolvableType);
// }
//
// public static boolean returnTypeIs(Method method, Class<?> returnType) {
// return ResolvableType.forClass(returnType)
// .isAssignableFrom(ResolvableType.forMethodReturnType(method));
// }
//
// public static boolean returnTypeIsAnyOf(Method method, Class<?>... returnTypes) {
// return Arrays.stream(returnTypes).anyMatch(returnType -> returnTypeIs(method, returnType));
// }
//
// }
// Path: src/main/java/io/github/polysantiago/spring/rest/SyncRequestHelper.java
import io.github.polysantiago.spring.rest.retry.RetryableException;
import io.github.polysantiago.spring.rest.support.SyntheticParametrizedTypeReference;
import io.github.polysantiago.spring.rest.util.ResolvableTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
package io.github.polysantiago.spring.rest;
@RequiredArgsConstructor
class SyncRequestHelper {
private final RestClientSpecification specification;
private final RestTemplate restTemplate;
private final Class<?> implementingClass;
@Setter
private boolean retryEnabled;
<T> Object executeRequest(MethodInvocation invocation, RequestEntity<T> requestEntity) {
try {
return executeRequestInternal(invocation, requestEntity);
} catch (HttpStatusCodeException ex) {
return handleHttpStatusCodeException(invocation.getMethod(), ex);
} catch (RuntimeException ex) {
throw handleRuntimeException(ex);
}
}
private RuntimeException handleRuntimeException(RuntimeException ex) {
if (retryEnabled && anyMatch(specification.getRetryableExceptions(), clazz -> clazz.isInstance(ex) || clazz.isInstance(getRootCause(ex)))) {
return new RetryableException(ex);
}
return ex;
}
private <T> Optional<T> handleHttpStatusCodeException(Method method, HttpStatusCodeException ex) {
HttpStatus statusCode = ex.getStatusCode(); | if (ResolvableTypeUtils.returnTypeIs(method, Optional.class) && statusCode.equals(HttpStatus.NOT_FOUND)) { |
polysantiago/spring-boot-rest-client | src/main/java/io/github/polysantiago/spring/rest/SyncRequestHelper.java | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryableException.java
// public class RetryableException extends RuntimeException {
//
// public RetryableException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/support/SyntheticParametrizedTypeReference.java
// @Getter
// @EqualsAndHashCode(callSuper = false)
// @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
// public class SyntheticParametrizedTypeReference<T> extends ParameterizedTypeReference<T> {
//
// private final Type type;
//
// public static <T> SyntheticParametrizedTypeReference<T> fromResolvableType(ResolvableType resolvedType) {
// if (resolvedType.hasGenerics()) {
// return new SyntheticParametrizedTypeReference<>(new SyntheticParametrizedType(resolvedType));
// }
// return new SyntheticParametrizedTypeReference<>(resolvedType.resolve());
// }
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/util/ResolvableTypeUtils.java
// @UtilityClass
// public class ResolvableTypeUtils {
//
// public static boolean typeIsAnyOf(ResolvableType resolvableType, Class<?>... classes) {
// return Arrays.stream(classes).anyMatch(clazz -> typeIs(resolvableType, clazz));
// }
//
// public static boolean typeIs(ResolvableType resolvableType, Class<?> clazz) {
// return ResolvableType.forClass(clazz).isAssignableFrom(resolvableType);
// }
//
// public static boolean returnTypeIs(Method method, Class<?> returnType) {
// return ResolvableType.forClass(returnType)
// .isAssignableFrom(ResolvableType.forMethodReturnType(method));
// }
//
// public static boolean returnTypeIsAnyOf(Method method, Class<?>... returnTypes) {
// return Arrays.stream(returnTypes).anyMatch(returnType -> returnTypeIs(method, returnType));
// }
//
// }
| import io.github.polysantiago.spring.rest.retry.RetryableException;
import io.github.polysantiago.spring.rest.support.SyntheticParametrizedTypeReference;
import io.github.polysantiago.spring.rest.util.ResolvableTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause; | }
private RuntimeException handleRuntimeException(RuntimeException ex) {
if (retryEnabled && anyMatch(specification.getRetryableExceptions(), clazz -> clazz.isInstance(ex) || clazz.isInstance(getRootCause(ex)))) {
return new RetryableException(ex);
}
return ex;
}
private <T> Optional<T> handleHttpStatusCodeException(Method method, HttpStatusCodeException ex) {
HttpStatus statusCode = ex.getStatusCode();
if (ResolvableTypeUtils.returnTypeIs(method, Optional.class) && statusCode.equals(HttpStatus.NOT_FOUND)) {
return Optional.empty();
}
if (retryEnabled && anyMatch(specification.getRetryableStatuses(), statusCode::equals)) {
throw new RetryableException(ex);
}
throw ex;
}
private <T> Object executeRequestInternal(MethodInvocation invocation, RequestEntity<T> requestEntity) {
Method method = invocation.getMethod();
if (hasPostLocation(method)) {
return postForLocation(requestEntity, method);
}
ResolvableType resolvedType = ResolvableType.forMethodReturnType(method, implementingClass);
if (ResolvableTypeUtils.returnTypeIsAnyOf(method, HttpEntity.class, ResponseEntity.class)) {
return exchangeForResponseEntity(resolvedType, requestEntity);
} | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryableException.java
// public class RetryableException extends RuntimeException {
//
// public RetryableException(Throwable cause) {
// super(cause);
// }
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/support/SyntheticParametrizedTypeReference.java
// @Getter
// @EqualsAndHashCode(callSuper = false)
// @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
// public class SyntheticParametrizedTypeReference<T> extends ParameterizedTypeReference<T> {
//
// private final Type type;
//
// public static <T> SyntheticParametrizedTypeReference<T> fromResolvableType(ResolvableType resolvedType) {
// if (resolvedType.hasGenerics()) {
// return new SyntheticParametrizedTypeReference<>(new SyntheticParametrizedType(resolvedType));
// }
// return new SyntheticParametrizedTypeReference<>(resolvedType.resolve());
// }
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/util/ResolvableTypeUtils.java
// @UtilityClass
// public class ResolvableTypeUtils {
//
// public static boolean typeIsAnyOf(ResolvableType resolvableType, Class<?>... classes) {
// return Arrays.stream(classes).anyMatch(clazz -> typeIs(resolvableType, clazz));
// }
//
// public static boolean typeIs(ResolvableType resolvableType, Class<?> clazz) {
// return ResolvableType.forClass(clazz).isAssignableFrom(resolvableType);
// }
//
// public static boolean returnTypeIs(Method method, Class<?> returnType) {
// return ResolvableType.forClass(returnType)
// .isAssignableFrom(ResolvableType.forMethodReturnType(method));
// }
//
// public static boolean returnTypeIsAnyOf(Method method, Class<?>... returnTypes) {
// return Arrays.stream(returnTypes).anyMatch(returnType -> returnTypeIs(method, returnType));
// }
//
// }
// Path: src/main/java/io/github/polysantiago/spring/rest/SyncRequestHelper.java
import io.github.polysantiago.spring.rest.retry.RetryableException;
import io.github.polysantiago.spring.rest.support.SyntheticParametrizedTypeReference;
import io.github.polysantiago.spring.rest.util.ResolvableTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
}
private RuntimeException handleRuntimeException(RuntimeException ex) {
if (retryEnabled && anyMatch(specification.getRetryableExceptions(), clazz -> clazz.isInstance(ex) || clazz.isInstance(getRootCause(ex)))) {
return new RetryableException(ex);
}
return ex;
}
private <T> Optional<T> handleHttpStatusCodeException(Method method, HttpStatusCodeException ex) {
HttpStatus statusCode = ex.getStatusCode();
if (ResolvableTypeUtils.returnTypeIs(method, Optional.class) && statusCode.equals(HttpStatus.NOT_FOUND)) {
return Optional.empty();
}
if (retryEnabled && anyMatch(specification.getRetryableStatuses(), statusCode::equals)) {
throw new RetryableException(ex);
}
throw ex;
}
private <T> Object executeRequestInternal(MethodInvocation invocation, RequestEntity<T> requestEntity) {
Method method = invocation.getMethod();
if (hasPostLocation(method)) {
return postForLocation(requestEntity, method);
}
ResolvableType resolvedType = ResolvableType.forMethodReturnType(method, implementingClass);
if (ResolvableTypeUtils.returnTypeIsAnyOf(method, HttpEntity.class, ResponseEntity.class)) {
return exchangeForResponseEntity(resolvedType, requestEntity);
} | SyntheticParametrizedTypeReference<T> responseType = SyntheticParametrizedTypeReference.fromResolvableType(resolvedType); |
polysantiago/spring-boot-rest-client | src/main/java/io/github/polysantiago/spring/rest/RestClientAutoConfiguration.java | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryOperationsInterceptorFactory.java
// @RequiredArgsConstructor
// public class RetryOperationsInterceptorFactory extends AbstractFactoryBean<RetryOperationsInterceptor> {
//
// private final RestClientProperties restClientProperties;
//
// @Override
// public Class<?> getObjectType() {
// return RetryOperationsInterceptor.class;
// }
//
// @Override
// protected RetryOperationsInterceptor createInstance() throws Exception {
// return new RetryInterceptor(restClientProperties.getRetry()).buildInterceptor();
// }
//
// }
| import io.github.polysantiago.spring.rest.retry.RetryOperationsInterceptorFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.retry.annotation.RetryConfiguration;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List; | return builder.build();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(RestTemplate.class)
public AsyncRestTemplate asyncRestClientTemplate(RestTemplate restTemplate) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setTaskExecutor(new SimpleAsyncTaskExecutor());
return new AsyncRestTemplate(requestFactory, restTemplate);
}
@Bean
public WebMvcConfigurer restClientWebMvcConfigurer(RestClientProperties properties) {
return new WebMvcConfigurerAdapter() {
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar dateTimeFormatterRegistrar = new DateTimeFormatterRegistrar();
dateTimeFormatterRegistrar.setUseIsoFormat(properties.getIsoDateTimeFormat());
dateTimeFormatterRegistrar.registerFormatters(registry);
}
};
}
@Configuration
@ConditionalOnBean(RetryConfiguration.class)
protected static class RestClientRetryConfiguration {
@Bean("restClientRetryInterceptor")
@ConditionalOnMissingBean | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetryOperationsInterceptorFactory.java
// @RequiredArgsConstructor
// public class RetryOperationsInterceptorFactory extends AbstractFactoryBean<RetryOperationsInterceptor> {
//
// private final RestClientProperties restClientProperties;
//
// @Override
// public Class<?> getObjectType() {
// return RetryOperationsInterceptor.class;
// }
//
// @Override
// protected RetryOperationsInterceptor createInstance() throws Exception {
// return new RetryInterceptor(restClientProperties.getRetry()).buildInterceptor();
// }
//
// }
// Path: src/main/java/io/github/polysantiago/spring/rest/RestClientAutoConfiguration.java
import io.github.polysantiago.spring.rest.retry.RetryOperationsInterceptorFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.retry.annotation.RetryConfiguration;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
return builder.build();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(RestTemplate.class)
public AsyncRestTemplate asyncRestClientTemplate(RestTemplate restTemplate) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setTaskExecutor(new SimpleAsyncTaskExecutor());
return new AsyncRestTemplate(requestFactory, restTemplate);
}
@Bean
public WebMvcConfigurer restClientWebMvcConfigurer(RestClientProperties properties) {
return new WebMvcConfigurerAdapter() {
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar dateTimeFormatterRegistrar = new DateTimeFormatterRegistrar();
dateTimeFormatterRegistrar.setUseIsoFormat(properties.getIsoDateTimeFormat());
dateTimeFormatterRegistrar.registerFormatters(registry);
}
};
}
@Configuration
@ConditionalOnBean(RetryConfiguration.class)
protected static class RestClientRetryConfiguration {
@Bean("restClientRetryInterceptor")
@ConditionalOnMissingBean | public RetryOperationsInterceptorFactory retryOperationInterceptorFactory(RestClientProperties properties) { |
polysantiago/spring-boot-rest-client | src/test/java/io/github/polysantiago/spring/rest/AbstractRestClientAsyncTest.java | // Path: src/test/java/io/github/polysantiago/spring/rest/AbstractRestClientAsyncTest.java
// interface AsyncFooClient {
//
// Future<String> defaultFoo();
//
// Future<String> foo(@PathVariable("id") String id, @RequestParam("query") String query);
//
// Future<Foo> getFoo(@PathVariable("id") String id);
//
// Future<List<Foo>> fooList();
//
// Future<Foo[]> fooArray();
//
// Future<Object> fooObject();
//
// Future<Foo> getFooWithAcceptHeader(@PathVariable("id") String id);
//
// Future<Void> bar(String body);
//
// Future<Void> barWithContentType(Foo foo);
//
// Future<Void> barPut(String body);
//
// Future<Void> barPatch(String body);
//
// Future<Void> barDelete(String body);
//
// Future<Optional<Foo>> tryNonEmptyOptional();
//
// Future<Optional<String>> tryEmptyOptional();
//
// Future<byte[]> raw();
//
// Future<Void> fooWithHeaders(@RequestHeader("User-Id") String userId,
// @RequestHeader("Password") String password);
//
// Future<ResponseEntity<String>> getEntity();
//
// Future<HttpEntity<String>> getHttpEntity();
//
// Future<URI> postForLocation(String body);
//
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.polysantiago.spring.rest.AbstractRestClientAsyncTest.AsyncFooClient;
import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.StringUtils.toEncodedString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Fail.fail;
import static org.springframework.test.web.client.MockRestServiceServer.createServer;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*; | package io.github.polysantiago.spring.rest;
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest | // Path: src/test/java/io/github/polysantiago/spring/rest/AbstractRestClientAsyncTest.java
// interface AsyncFooClient {
//
// Future<String> defaultFoo();
//
// Future<String> foo(@PathVariable("id") String id, @RequestParam("query") String query);
//
// Future<Foo> getFoo(@PathVariable("id") String id);
//
// Future<List<Foo>> fooList();
//
// Future<Foo[]> fooArray();
//
// Future<Object> fooObject();
//
// Future<Foo> getFooWithAcceptHeader(@PathVariable("id") String id);
//
// Future<Void> bar(String body);
//
// Future<Void> barWithContentType(Foo foo);
//
// Future<Void> barPut(String body);
//
// Future<Void> barPatch(String body);
//
// Future<Void> barDelete(String body);
//
// Future<Optional<Foo>> tryNonEmptyOptional();
//
// Future<Optional<String>> tryEmptyOptional();
//
// Future<byte[]> raw();
//
// Future<Void> fooWithHeaders(@RequestHeader("User-Id") String userId,
// @RequestHeader("Password") String password);
//
// Future<ResponseEntity<String>> getEntity();
//
// Future<HttpEntity<String>> getHttpEntity();
//
// Future<URI> postForLocation(String body);
//
// }
// Path: src/test/java/io/github/polysantiago/spring/rest/AbstractRestClientAsyncTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.polysantiago.spring.rest.AbstractRestClientAsyncTest.AsyncFooClient;
import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.StringUtils.toEncodedString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Fail.fail;
import static org.springframework.test.web.client.MockRestServiceServer.createServer;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
package io.github.polysantiago.spring.rest;
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest | public abstract class AbstractRestClientAsyncTest<T extends AsyncFooClient> { |
polysantiago/spring-boot-rest-client | src/test/java/io/github/polysantiago/spring/rest/RestClientPropertiesTest.java | // Path: src/main/java/io/github/polysantiago/spring/rest/retry/BackOffSettings.java
// @Getter
// @Setter
// public class BackOffSettings {
//
// private long delay = 1000;
// private long maxDelay;
// private double multiplier;
// private boolean random;
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetrySettings.java
// @Getter
// @Setter
// public class RetrySettings {
//
// private int maxAttempts = 3;
// private BackOffSettings backOff = new BackOffSettings();
//
// }
| import io.github.polysantiago.spring.rest.retry.BackOffSettings;
import io.github.polysantiago.spring.rest.retry.RetrySettings;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment; | registerAndRefresh();
assertProperties(getProperties(), 5, 1000L, 0L, 0.0d, false);
}
@Test
public void testBackOffSettings() throws Exception {
addEnvironment(this.context, "spring.rest.client.retry.back-off.delay:2000");
addEnvironment(this.context, "spring.rest.client.retry.back-off.max-delay:10000");
addEnvironment(this.context, "spring.rest.client.retry.back-off.multiplier:2.5");
addEnvironment(this.context, "spring.rest.client.retry.back-off.random:true");
registerAndRefresh();
assertProperties(getProperties(), 3, 2000L, 10000L, 2.5d, true);
}
private RestClientProperties getProperties() {
return this.context.getBean(RestClientProperties.class);
}
private void registerAndRefresh() {
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
}
private static void assertProperties(RestClientProperties properties,
int maxAttempts, long delay, long maxDelay, double multiplier, boolean random) {
assertThat(properties).isNotNull();
| // Path: src/main/java/io/github/polysantiago/spring/rest/retry/BackOffSettings.java
// @Getter
// @Setter
// public class BackOffSettings {
//
// private long delay = 1000;
// private long maxDelay;
// private double multiplier;
// private boolean random;
//
// }
//
// Path: src/main/java/io/github/polysantiago/spring/rest/retry/RetrySettings.java
// @Getter
// @Setter
// public class RetrySettings {
//
// private int maxAttempts = 3;
// private BackOffSettings backOff = new BackOffSettings();
//
// }
// Path: src/test/java/io/github/polysantiago/spring/rest/RestClientPropertiesTest.java
import io.github.polysantiago.spring.rest.retry.BackOffSettings;
import io.github.polysantiago.spring.rest.retry.RetrySettings;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;
registerAndRefresh();
assertProperties(getProperties(), 5, 1000L, 0L, 0.0d, false);
}
@Test
public void testBackOffSettings() throws Exception {
addEnvironment(this.context, "spring.rest.client.retry.back-off.delay:2000");
addEnvironment(this.context, "spring.rest.client.retry.back-off.max-delay:10000");
addEnvironment(this.context, "spring.rest.client.retry.back-off.multiplier:2.5");
addEnvironment(this.context, "spring.rest.client.retry.back-off.random:true");
registerAndRefresh();
assertProperties(getProperties(), 3, 2000L, 10000L, 2.5d, true);
}
private RestClientProperties getProperties() {
return this.context.getBean(RestClientProperties.class);
}
private void registerAndRefresh() {
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
}
private static void assertProperties(RestClientProperties properties,
int maxAttempts, long delay, long maxDelay, double multiplier, boolean random) {
assertThat(properties).isNotNull();
| RetrySettings retry = properties.getRetry(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.