fix dateNtime and fileupload issue
This commit is contained in:
+36
-1
@@ -14,6 +14,10 @@ import java.util.stream.Collectors;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -36,7 +40,7 @@ import com.realnet.FileUpload.Services.FileuploadService;
|
||||
import com.realnet.FileUpload.Services.UploadedFileService;
|
||||
|
||||
@RequestMapping(value = "/FileUpload")
|
||||
//@CrossOrigin("*")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class UploadeddocsController {
|
||||
@Autowired
|
||||
@@ -125,6 +129,37 @@ public class UploadeddocsController {
|
||||
return get;
|
||||
}
|
||||
|
||||
@GetMapping("/files/{filename:.+}")
|
||||
public ResponseEntity<Resource> getFile(@PathVariable String filename) {
|
||||
try {
|
||||
Path filePath = Paths.get(projectPath, "Resources", "Files", filename).normalize();
|
||||
File file = filePath.toFile();
|
||||
if (!file.exists()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
Resource resource = new UrlResource(filePath.toUri());
|
||||
String contentType = Files.probeContentType(filePath);
|
||||
if (contentType == null) {
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(contentType))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"")
|
||||
.body(resource);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/view/{id}")
|
||||
public ResponseEntity<Resource> getFileById(@PathVariable Integer id) {
|
||||
Uploadeddocs doc = Service.getdetailsbyId(id);
|
||||
if (doc == null || doc.getUploadedfile_name() == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
return getFile(doc.getUploadedfile_name());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@@ -7,33 +7,52 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.realnet.logging.NoLogging;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
// @Bean
|
||||
// public HibernateJpaSessionFactoryBean sessionFactory() {
|
||||
// return new HibernateJpaSessionFactoryBean();
|
||||
// }
|
||||
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("[MM/dd/yyyy][yyyy-MM-dd][dd/MM/yyyy]");
|
||||
private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("[yyyy-MM-dd'T'HH:mm:ss][yyyy-MM-dd HH:mm:ss][MM/dd/yyyy HH:mm:ss]");
|
||||
|
||||
@NoLogging
|
||||
@Bean
|
||||
public ModelMapper modelMapper() {
|
||||
return new ModelMapper();
|
||||
}
|
||||
|
||||
private ObjectMapper configureMapper(ObjectMapper mapper) {
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DATE_FORMAT));
|
||||
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("MM/dd/yyyy")));
|
||||
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DATE_TIME_FORMAT));
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
mapper.registerModule(javaTimeModule);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(mapper);
|
||||
return converter;
|
||||
ObjectMapper mapper = configureMapper(new ObjectMapper());
|
||||
return new MappingJackson2HttpMessageConverter(mapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
|
||||
return configureMapper(new ObjectMapper());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
web.ignoring().antMatchers("/", "/resources/**", "/static/**", "/public/**", "/webui/**", "/h2-console/**",
|
||||
"/configuration/**", "/swagger-ui/**", "/swagger-resources/**", "/webjars/**", "/api-docs",
|
||||
"/api-docs/**", "/v2/api-docs/**", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/**/*.png",
|
||||
"/**/*.jpg", "/**/*.gif", "/**/*.svg", "/**/*.ico", "/**/*.ttf", "/**/*.woff", "/**/*.otf");
|
||||
"/**/*.jpg", "/**/*.gif", "/**/*.svg", "/**/*.ico", "/**/*.ttf", "/**/*.woff", "/**/*.otf", "/FileUpload/files/**", "/FileUpload/view/**");
|
||||
}
|
||||
|
||||
// }
|
||||
@@ -125,7 +125,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
// Add CORS Filter //http.cors().and().csrf().disable().
|
||||
.addFilterBefore(new CorsFilter(), ChannelProcessingFilter.class)
|
||||
// adding backend/token for single container by Azmat 27-08
|
||||
.authorizeRequests(requests -> requests.antMatchers("/token/**", "/backend/token/**", "/**/backend/token/**").permitAll().antMatchers("/log2/**")
|
||||
.authorizeRequests(requests -> requests.antMatchers("/token/**", "/backend/token/**", "/**/backend/token/**", "/FileUpload/files/**", "/FileUpload/view/**").permitAll().antMatchers("/log2/**")
|
||||
.permitAll().antMatchers("/api/**").permitAll()
|
||||
// .antMatchers("/SqlworkbenchSqlcont/**").hasRole("ADMIN")
|
||||
.anyRequest().authenticated())
|
||||
|
||||
@@ -5,14 +5,7 @@ import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.realnet.io8ref.Xyz.Entity.Xyz;
|
||||
import com.realnet.io8ref.Xyz.Services.XyzService;
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
package com.realnet.io8ref.Xyz.Entity;
|
||||
import lombok.*;
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import lombok.*;
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
|
||||
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@@ -13,17 +23,6 @@ package com.realnet.io8ref.Xyz.Entity;
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String email;
|
||||
private Double price;
|
||||
private Long quantity;
|
||||
private LocalDate dob;
|
||||
private LocalDateTime createdAt;
|
||||
private Boolean active;
|
||||
private String status;
|
||||
private String tags;
|
||||
private String photo;
|
||||
private Long categoryId;
|
||||
/* {{FORM_FIELDS}} */
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user