Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazariii committed Nov 2, 2015
1 parent 808adfc commit a9c2127
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public List<Locality> findByDistrictIdAndOrganizationId(Long districtId, Long or
return localityRepository.findByDistrictIdAndOrganizationId(districtId, organizationId);
}

/**
* Finds all localities by organization id
*
* @param organizationId id of organizaton
* @return list of localities
*/
@Override
@Transactional(readOnly = true)
public List<Locality> findLocalitiesByOrganizationId(Long organizationId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public Region getRegionByDesignation(String designation) {
return regionRepository.findByDesignation(designation);
}

/**
* Find region by district id
* @param districtId id of district
* @return region
*/
@Override
public Region findByDistrictId(Long districtId) {
return regionRepository.findByDistrictId(districtId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import java.util.Set;
import java.util.stream.Collectors;


/**
* @author Nazarii Ivashkiv
* Class for converting types
*/
public class TypeConverter {

Expand Down Expand Up @@ -39,6 +38,11 @@ public static <T extends Enum<T>> Set<T> stringToEnum(Set<String> strings, Class
return res;
}

/**
* Convert object to map of its fields and values
* @param object for converting
* @return map of fields and values
*/
public static Map<String, String> ObjectToMap(Object object) {
ObjectMapper objectMapper = new ObjectMapper();

Expand All @@ -49,15 +53,4 @@ public static Map<String, String> ObjectToMap(Object object) {
.collect(Collectors.toMap(Map.Entry::getKey, newEntry -> String.valueOf(newEntry.getValue())));
}

/*public static <T> Map<String, Object> ObjectToMap(Object object) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
Map<String, Object> objectAsMap = new HashMap<>();
BeanInfo info = Introspector.getBeanInfo(object.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
Method reader = pd.getReadMethod();
if (reader != null)
objectAsMap.put(pd.getName(), reader.invoke(object));
}
return objectAsMap;
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public PageDTO<AgreementDTO> pageDeviceCategoryWithSearch(@PathVariable Integer
return new PageDTO<>(queryResult.getTotalItems(), content);
}

/**
* Return page of agreements
* @param pageNumber number of page to return
* @param itemsPerPage count of items on page
* @return page of agreement
*/
@RequestMapping(value = "{pageNumber}/{itemsPerPage}", method = RequestMethod.GET)
public PageDTO<AgreementDTO> getDeviceCategoryPage(@PathVariable Integer pageNumber, @PathVariable Integer itemsPerPage) {
return pageDeviceCategoryWithSearch(pageNumber, itemsPerPage, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public ResponseEntity addOrganization(
* Fetch required data for all organization depends on received {@param pageNumber}, {@param itemsPerPage},
* {@param sortCriteria} {@param sortOrder} and {@param searchData} that contains fields must be filtered
*
* @param pageNumber
* @param itemsPerPage
* @param sortCriteria
* @param sortOrder
* @param searchData
* @param pageNumber number of page to return
* @param itemsPerPage count of items on page
* @param sortCriteria sorting criteria
* @param sortOrder order of sorting
* @param searchData filtering data
* @return PageDTO that contains required data about current organizations depends on received filter, sort ,pagination and items per page
*/
@RequestMapping(value = "{pageNumber}/{itemsPerPage}/{sortCriteria}/{sortOrder}", method = RequestMethod.GET)
Expand Down Expand Up @@ -151,7 +151,7 @@ public PageDTO<OrganizationPageItem> getOrganizationsPage(
/**
* Fetch data depends on organization with received {@param id}
*
* @param id
* @param id id of organizaton
* @return OrganizationDTO
*/
@RequestMapping(value = "getOrganization/{id}")
Expand All @@ -170,10 +170,9 @@ public OrganizationDTO getOrganization(@PathVariable("id") Long id) {
.map(Device.DeviceType::name)
.forEach(counters::add);

OrganizationDTO organizationDTO = new OrganizationDTO(organization.getId(), organization.getName(), organization.getEmail(), organization.getPhone(), types, counters,
return new OrganizationDTO(organization.getId(), organization.getName(), organization.getEmail(), organization.getPhone(), types, counters,
organization.getEmployeesCapacity(), organization.getMaxProcessTime(), organization.getAddress().getRegion(), organization.getAddress().getDistrict(), organization.getAddress().getLocality(),
organization.getAddress().getStreet(), organization.getAddress().getBuilding(), organization.getAddress().getFlat());
return organizationDTO;
}

/**
Expand Down Expand Up @@ -218,7 +217,7 @@ public ResponseEntity editOrganization(
organization.getMiddleName(),
adminName,
organization.getServiceAreas());
} catch ( UnsupportedEncodingException | MessagingException e) {
} catch (UnsupportedEncodingException | MessagingException e) {
logger.error("Got exeption while editing organization ", e);
httpStatus = HttpStatus.CONFLICT;
}
Expand All @@ -236,7 +235,7 @@ public ResponseEntity editOrganization(
/**
* Fetch organization admin data depends on organization with id {@param id}
*
* @param id
* @param id id of organizaton
* @return OrganizationAdminDTO
*/
@RequestMapping(value = "getOrganizationAdmin/{id}")
Expand Down Expand Up @@ -270,7 +269,7 @@ public OrganizationAdminDTO getAdmin(@PathVariable("id") Long id) {
/**
* Fetch organization edit history for organization with {@param organizationId}
*
* @param organizationId
* @param organizationId id of organizaton
* @return PageDTO<OrganizationEditHistoryPageDTO>
*/
@RequestMapping(value = "edit/history/{organizationId}")
Expand All @@ -280,18 +279,37 @@ public PageDTO<OrganizationEditHistoryPageDTO> getEditHistory(@PathVariable("org
return new PageDTO<>(OrganizationEditPageDTOTransformer.toDtoFromList(organizationEditHistoryList));
}

/**
* Finds all localities by organization id
*
* @param organizationId id of organizaton
* @return list of localities
*/
@RequestMapping(value = "serviceArea/localities/{organizationId}", method = RequestMethod.GET)
public List<LocalityDTO> getServiceAreaLocaities(@PathVariable("organizationId") Long organizationId) {
return localityService.findLocalitiesByOrganizationId(organizationId).stream()
.map(locality -> new LocalityDTO(locality.getId(), locality.getDesignation(), locality.getDistrict().getId()))
.collect(Collectors.toList());
}

/**
* Find region by district id
*
* @param districtId id of district
* @return region
*/
@RequestMapping(value = "serviceArea/region/{districtId}", method = RequestMethod.GET)
public Region getServiceAreaRegion(@PathVariable("districtId") Long districtId) {
return regionService.findByDistrictId(districtId);
}

/**
* Find all organizations by organization types and device types
*
* @param organizationType type of organization
* @param deviceType type of device
* @return list of organization wraped in ApplicationFieldDTO
*/
@RequestMapping(value = "getOrganization/{organizationType}/{deviceType}", method = RequestMethod.GET)
public List<ApplicationFieldDTO> getOrganizationByOrganizationTypeAndDeviceType(@PathVariable("organizationType") String organizationType,
@PathVariable("deviceType") String deviceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.softserve.edu.controller.client.application.util.CatalogueDTOTransformer;
import com.softserve.edu.dto.application.ApplicationFieldDTO;
import com.softserve.edu.service.catalogue.LocalityService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -14,7 +13,6 @@

@RestController
public class LocalityController {
Logger logger = Logger.getLogger(LocalityController.class);

@Autowired
private LocalityService localityService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.softserve.edu.entity.verification.ClientData;
import com.softserve.edu.entity.verification.Verification;
import com.softserve.edu.service.admin.OrganizationService;
import com.softserve.edu.service.calibrator.CalibratorService;
import com.softserve.edu.service.provider.ProviderService;
import com.softserve.edu.service.tool.DeviceService;
import com.softserve.edu.service.tool.MailService;
Expand Down Expand Up @@ -55,9 +54,6 @@ public class ClientApplicationController {
@Autowired
private ProviderService providerService;

@Autowired
private CalibratorService calibratorService;

@Autowired
private DeviceService deviceService;

Expand Down Expand Up @@ -125,8 +121,8 @@ public VerificationDTO getVerificationCode(@PathVariable String verificationId)
/**
* Find Providers corresponding to Locality
*
* @param localityId
* @return
* @param localityId id of locality
* @return list of providers wrapped in ApplicationFieldDTO
*/
@RequestMapping(value = "providersInLocality/{localityId}", method = RequestMethod.GET)
public List<ApplicationFieldDTO> getProvidersCorrespondingLocality(@PathVariable Long localityId) {
Expand All @@ -139,9 +135,9 @@ public List<ApplicationFieldDTO> getProvidersCorrespondingLocality(@PathVariable
/**
* Return all providers in locality by device type
*
* @param localityId
* @param deviceType
* @return
* @param localityId id of locality
* @param deviceType type of device
* @return list of providers wrapped in ApplicationFieldDTO
*/
@RequestMapping(value = "providers/{localityId}/{deviceType}", method = RequestMethod.GET)
public List<ApplicationFieldDTO> getProvidersCorrespondingLocalityAndType(@PathVariable Long localityId, @PathVariable String deviceType) {
Expand All @@ -152,13 +148,14 @@ public List<ApplicationFieldDTO> getProvidersCorrespondingLocalityAndType(@PathV

/**
* Return calibrators corresponding organization and device type
*
* @param type type of device.
* @param user user of current organization
* @return set of ApplicationFieldDTO where stored organization id and name
*/
@RequestMapping(value = "calibrators/{type}", method = RequestMethod.GET)
public Set<ApplicationFieldDTO> getCalibratorsCorrespondingDeviceType(@PathVariable String type,
@AuthenticationPrincipal SecurityUserDetailsService.CustomUserDetails user) {
@AuthenticationPrincipal SecurityUserDetailsService.CustomUserDetails user) {
//todo agreement
return organizationService.findByIdAndTypeAndActiveAgreementDeviceType(user.getOrganizationId(), OrganizationType.CALIBRATOR, Device.DeviceType.valueOf(type))
.stream()
Expand All @@ -169,7 +166,7 @@ public Set<ApplicationFieldDTO> getCalibratorsCorrespondingDeviceType(@PathVaria
/**
* return all devices
*
* @return
* @return ist of devices wrapped into DeviceLightDTO
*/
@RequestMapping(value = "devices", method = RequestMethod.GET)
public List<DeviceLightDTO> getAll() {
Expand All @@ -178,6 +175,12 @@ public List<DeviceLightDTO> getAll() {
.collect(Collectors.toList());
}

/**
* Return all divices by type
*
* @param deviceType type of devices
* @return list of devices wrapped into ApplicationFieldDTO
*/
@RequestMapping(value = "devices/{deviceType}", method = RequestMethod.GET)
public List<ApplicationFieldDTO> getAllByType(@PathVariable String deviceType) {
return deviceService.getAllByType(deviceType).stream()
Expand All @@ -188,8 +191,8 @@ public List<ApplicationFieldDTO> getAllByType(@PathVariable String deviceType) {
/**
* Sends email to System Administrator from client with verification application
*
* @param mailDto
* @return
* @param mailDto mail body
* @return status
*/
@RequestMapping(value = "clientMessage", method = RequestMethod.POST)
public String sentMailFromClient(@RequestBody ClientMailDTO mailDto) {
Expand All @@ -212,8 +215,8 @@ public String sentMailFromClient(@RequestBody ClientMailDTO mailDto) {
* when there is no provider in database for specified location (for example district)
* and client wants to send a message
*
* @param mailDto
* @return
* @param mailDto mail body
* @return status
*/
@RequestMapping(value = "clientMessageNoProvider", method = RequestMethod.POST)
public String sentMailFromClientNoProvider(@RequestBody ClientMailDTO mailDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,6 @@ angular
}
});
}


};

}

]);

0 comments on commit a9c2127

Please sign in to comment.