Skip to content

Commit

Permalink
Moved New API in PATCH method in order to get Application details and…
Browse files Browse the repository at this point in the history
… update application endpoints.
  • Loading branch information
vertigo17 committed Dec 27, 2023
1 parent 7b90670 commit dc89b19
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -116,7 +117,7 @@ public ResponseWrapper<CountryEnvironmentParametersDTOV001> findApplicationEnvir
@JsonView(View.Public.GET.class)
@ResponseStatus(HttpStatus.OK)
@PutMapping(path = "/{application}/{country}/{environment}", headers = {API_VERSION_1}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseWrapper<CountryEnvironmentParametersDTOV001> update(
public ResponseWrapper<CountryEnvironmentParametersDTOV001> updatePUT(
@PathVariable("application") String applicationId,
@PathVariable("country") String countryId,
@PathVariable("environment") String environmentId,
Expand All @@ -134,7 +135,7 @@ public ResponseWrapper<CountryEnvironmentParametersDTOV001> update(

return ResponseWrapper.wrap(
this.applicationEnvironmentMapper.toDTO(
this.applicationEnvironmentApiService.updateApplicationEnvironmentAPI(
this.applicationEnvironmentApiService.updateApplicationEnvironmentPUT(
system,
applicationId,
countryId,
Expand All @@ -145,4 +146,37 @@ public ResponseWrapper<CountryEnvironmentParametersDTOV001> update(
);
}

@ApiOperation("Update an application environment")
@ApiResponse(code = 200, message = "ok")
@JsonView(View.Public.GET.class)
@ResponseStatus(HttpStatus.OK)
@PatchMapping(path = "/{application}/{country}/{environment}", headers = {API_VERSION_1}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseWrapper<CountryEnvironmentParametersDTOV001> updatePATCH(
@PathVariable("application") String applicationId,
@PathVariable("country") String countryId,
@PathVariable("environment") String environmentId,
@Valid @JsonView(View.Public.PATCH.class) @RequestBody CountryEnvironmentParametersDTOV001 applicationEnvironmentToUpdate,
@RequestHeader(name = API_KEY, required = false) String apiKey,
Principal principal) throws CerberusException {

this.apiAuthenticationService.authenticate(principal, apiKey);
// We first get the application in order to retreive the system.
Application applicationObj = this.applicationApiService.readByKey(applicationId);
if (applicationObj == null) {
throw new EntityNotFoundException(Application.class, "application", applicationId);
}
String system = applicationObj.getSystem();

return ResponseWrapper.wrap(
this.applicationEnvironmentMapper.toDTO(
this.applicationEnvironmentApiService.updateApplicationEnvironmentPATCH(
system,
applicationId,
countryId,
environmentId,
this.applicationEnvironmentMapper.toEntity(applicationEnvironmentToUpdate),
principal
))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,68 +40,68 @@
public class ApplicationDTOV001 {

@NotEmpty
@JsonView(value = {View.Public.GET.class, View.Public.POST.class, View.Public.PUT.class,})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 0)
private String application;

@ApiModelProperty(position = 1)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String description;

@ApiModelProperty(position = 2)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private Integer sort;

@ApiModelProperty(position = 3)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String type;

@ApiModelProperty(position = 4)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String system;

@ApiModelProperty(position = 5)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String subsystem;

@ApiModelProperty(position = 6)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String svnurl;

@ApiModelProperty(position = 7)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String bugTrackerUrl;

@ApiModelProperty(position = 8)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String bugTrackerNewUrl;

@ApiModelProperty(position = 9)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private Integer poolSize;

@ApiModelProperty(position = 10)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String deploytype;

@ApiModelProperty(position = 11)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String mavengroupid;

@ApiModelProperty(position = 12)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private List<CountryEnvironmentParametersDTOV001> environments;

@ApiModelProperty(position = 17)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String usrCreated;

@ApiModelProperty(position = 19)
@JsonView(value = {View.Public.GET.class})
private String dateCreated;

@ApiModelProperty(position = 20)
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
private String usrModif;

@ApiModelProperty(position = 21)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,61 +45,61 @@ public class CountryEnvironmentParametersDTOV001 {
private String system;

@NotEmpty
@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class,})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class,})
@ApiModelProperty(position = 1)
private String country;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 2)
private String environment;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 3)
private String application;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 4)
@JsonProperty("host")
private String ip;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 5)
@JsonProperty("contextRoot")
private String url;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 6)
private String urlLogin;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 7)
private String domain;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 8)
private String var1;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 9)
private String var2;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 10)
private String var3;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 11)
private String var4;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 12)
private int poolSize;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 13)
private String mobileActivity;

@JsonView(value = {View.Public.GET.class, View.Public.PUT.class, View.Public.POST.class})
@JsonView(value = {View.Public.GET.class, View.Public.PATCH.class, View.Public.PUT.class, View.Public.POST.class})
@ApiModelProperty(position = 14)
private String mobilePackage;

Expand All @@ -112,7 +112,7 @@ public class CountryEnvironmentParametersDTOV001 {
private String dateCreated;

@JsonView(value = {View.Public.GET.class})
@ApiModelProperty(example = "a03e2ae7-6fe6-42df-b2d6-6f7542ee3ed3", position = 17)
@ApiModelProperty(example = "cerberus", position = 17)
private String usrModif;

@JsonView(value = {View.Public.GET.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/

package org.cerberus.core.api.dto.views;

public interface View {

interface Public {

interface POST {
}

interface PUT {
}

interface PATCH {
}

interface GET {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cerberus.core.api.exceptions.EntityNotFoundException;
import org.cerberus.core.api.exceptions.InvalidRequestException;
import org.cerberus.core.crud.entity.CountryEnvironmentParameters;
import org.cerberus.core.crud.service.ICountryEnvironmentParametersService;
import org.cerberus.core.exception.CerberusException;
Expand Down Expand Up @@ -55,14 +56,9 @@ public CountryEnvironmentParameters readByKey(String system, String application,
return cep.getItem();
}

public CountryEnvironmentParameters updateApplicationEnvironmentAPI(String system, String applicationId, String countryId, String environmentId,
public CountryEnvironmentParameters updateApplicationEnvironmentPATCH(String system, String applicationId, String countryId, String environmentId,
CountryEnvironmentParameters newApplicationEnvironment, Principal principal) throws CerberusException {

// LOG.debug(applicationId);
// LOG.debug(countryId);
// LOG.debug(environmentId);
// LOG.debug(newApplicationEnvironment);

AnswerItem<CountryEnvironmentParameters> cep = this.applicationEnvironmentService.readByKey(system, countryId, environmentId, applicationId);
if (cep.getItem() == null) {
LOG.debug("not exist.");
Expand All @@ -88,9 +84,32 @@ public CountryEnvironmentParameters updateApplicationEnvironmentAPI(String syste

newApplicationEnvironment.setPoolSize(0 == newApplicationEnvironment.getPoolSize() ? cep.getItem().getPoolSize() : newApplicationEnvironment.getPoolSize());

// LOG.debug(newApplicationEnvironment);
applicationEnvironmentService.update(newApplicationEnvironment);

return this.applicationEnvironmentService.readByKey(system, countryId, environmentId, applicationId).getItem();
}

public CountryEnvironmentParameters updateApplicationEnvironmentPUT(String system, String applicationId, String countryId, String environmentId,
CountryEnvironmentParameters newApplicationEnvironment, Principal principal) throws CerberusException {

AnswerItem<CountryEnvironmentParameters> cep = this.applicationEnvironmentService.readByKey(system, countryId, environmentId, applicationId);
if (cep.getItem() == null) {
LOG.debug("not exist.");
throw new EntityNotFoundException(CountryEnvironmentParameters.class, "system", system, "application", applicationId, "country", countryId, "environment", environmentId);
}
LOG.debug("Exist.");

newApplicationEnvironment.setUsrModif(principal.getName());
newApplicationEnvironment.setSystem(system);
newApplicationEnvironment.setCountry(countryId);
newApplicationEnvironment.setEnvironment(environmentId);
newApplicationEnvironment.setApplication(applicationId);

try {
applicationEnvironmentService.convert(applicationEnvironmentService.update(newApplicationEnvironment));
} catch (CerberusException e) {
throw new InvalidRequestException("Missing data from Entity resulting : " + e.getMessage());
}

return this.applicationEnvironmentService.readByKey(system, countryId, environmentId, applicationId).getItem();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public Answer update(CountryEnvironmentParameters object) {
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to execute query : " + exception.toString()));
} finally {
preStat.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,6 @@ public void convert(Answer answer) throws CerberusException {
//if the service returns an OK message then we can get the item
return;
}
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR_WITH_DETAIL).resolveDescription("DETAIL", answer.getMessageDescription()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum MessageGeneralEnum {
DATA_OPERATION_SUCCESS(000, MessageCodeEnum.GENERIC_CODE_SUCCESS.getCodeString(), "The requested operation was concluded with success."),
DATA_OPERATION_WARNING(000, MessageCodeEnum.GENERIC_CODE_WARNING.getCodeString(), "The requested operation was concluded but with warnings."),
DATA_OPERATION_ERROR(900, MessageCodeEnum.GENERIC_CODE_ERROR.getCodeString(), "An error occurred while executing the requested operation !"),
DATA_OPERATION_ERROR_WITH_DETAIL(900, MessageCodeEnum.GENERIC_CODE_ERROR.getCodeString(), "An error occurred while executing the requested operation ! %DETAIL%"),
DATA_OPERATION_ERROR_WITH_REQUEST(900, MessageCodeEnum.GENERIC_CODE_ERROR.getCodeString(), "An error occurred while executing the requested operation ! request : %REQUEST%."),
DATA_OPERATION_ERROR_DUPLICATE(900, MessageCodeEnum.GENERIC_CODE_ERROR.getCodeString(), "The %ITEM% that you are trying to %OPERATION% conflicts with an existing one! Please check for duplicates! %REASON%"),
GENERIC_SUCCESS(000, MessageCodeEnum.GENERIC_CODE_SUCCESS.getCodeString(), "The requested operation was concluded with success."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Added support for a couple of new actions on Selenium IDE import. #2498
* Added possibility to get base64 value from application object using syntax : %object.OBJNAME.base64%. That allow to use object pictures as file upload on test cases.
* New API in order to get Application details and update application endpoints.
* Preselect country environment and robot on rerun testcase modal.


*Warning to be considered before applying the version (deprecated features)*
Expand Down

0 comments on commit dc89b19

Please sign in to comment.